CentOS 7 installs Mysql and sets the method to boot from startup
- 2020-05-24 06:42:20
- OfStack
CentOS 7 no longer has an Mysql database; the default database is MariaDB (a branch of Mysql).
You can manually install the Mysql database by following these steps.
1. Download the rpm installation file
wget http://repo.mysql.com/mysql-community-release-el7.rpm
2. Perform the rpm installation
rpm -ivh mysql-community-release-el7.rpm
When dependency resolution is complete, the following options appear:
Dependencies Resolved
==============================================================================================================
Package Arch Version Repository Size
==============================================================================================================
Installing:
mysql-community-libs x86_64 5.6.32-2.el7 mysql56-community 2.0 M
replacing mariadb-libs.x86_64 1:5.5.47-1.el7_2
mysql-community-server x86_64 5.6.32-2.el7 mysql56-community 59 M
Installing for dependencies:
mysql-community-client x86_64 5.6.32-2.el7 mysql56-community 19 M
mysql-community-common x86_64 5.6.32-2.el7 mysql56-community 256 k
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Transaction Summary
=============================================================================================================
Install 2 Packages (+8 Dependent packages)
Total download size: 82 M
Is this ok [y/d/N]:
3. As you can see, both server and client have been selected for installation. Select y to download and install automatically.
4. When the installation is complete, start Mysql.
systemctl start mysqld.service
5. Set the root password.
update user set password=password("123456") where user='root';
6. Start from startup.
vim /etc/rc.local
add service mysqld start
7. Important updates:
The new rpm installation file does not have the script for the automatic yum installation, so you need to manually perform the yum installation.
After step 2, just execute yum install mysql-server.
8. About self-starting
Step 6 only applies if mysqld is not self-booting.
If mysql is self-booted by default, there may be problems with the self-booting in rc.local such as out-of-order.
A more secure solution is as follows:
Problem with CentOS 7 program startup
1. Problem phenomena:
After system restart, it was found that the mysqld service started normally, but the application A, which relies on the mysql database, failed to start.
Viewing the log shows that the program A failed to connect to the database when it started.
2. Reason analysis:
The mysqld service started normally.
At this point, manually restart the program A, and A is also running normally.
Conclusion: this means that when the program A is started, mysqld may not be started.
3. Startup sequence
The first thing that came to mind was tweaking the startup order of the mysqld service to make it higher than my application A.
However, no startup script for mysqld was found under the /etc/ init.d path.
4. Work your way through
The mysqld installation that follows the link is automatically started by default.
You can unboot mysqld and write a startup script to make sure it starts before A starts.
5. Solutions
1. View the system's current default method of starting a project, not setup or something like that.
systemctl list-unit-files
Execute this command to view the current system's service startup and service status.
The results are as follows:
...
microcode.service enabled
mysql.service enabled
mysqld.service enabled
NetworkManager-dispatcher.service enabled
...
2. Cancel the self-booting of mysqld
systemctl disable mysqld
After executing this command, check the service status of the current system:
...
microcode.service enabled
mysqld.service disabled
NetworkManager-dispatcher.service enabled
...
3. Custom /etc/ rc.local
First, execute systemctl start mysqld
Perform startA