To install MySQL 5.x version, for example, the operating system version is CentOS Linux release 7.7.1908 (Core).
First, if there is already mysql-server checks yum source,
# Command line execution yum update rpm -qa | grep mysql # Command line display mysql-community-client-5.6.36-2.el5.x86_64 mysql-community-common-5.6.36-2.el5.x86_64 mysql-community-server-5.6.36-2.el5.x86_64 mysql-community-release-el5-7.noarch mysql-community-libs-5.6.36-2.el5.x86_64 mysql-5.6.36-2.el5.x86_64 mysql-community-libs-compat-5.6.36-2.el5.x86_64 # If you do not see mysql-server to add the source into the second step, I installed here, so already we have. # If your system also has a display, you can skip the second step.
Second, add source mysql-server
# 1. First download rpm, mysql source directory is: http: //repo.mysql.com/, you can copy the appropriate rpm according to the version needs its own address wget http://repo.mysql.com/mysql-community-release-el5-7.noarch.rpm # 2. Installation Source rpm -ivh mysql-community-release-el5-7.noarch.rpm
Third, install and start mysql-server
# Command line execution yum install mysql-server # View service startup state service mysqld status # Default profile here vim /etc/my.cnf # Start command service mysqld start # Reboot command service mysqld restart # Stop command service mysqld stop
Fourth, the profile settings
# Open the configuration file vim my.cnf # Key configuration items [mysqld] port = 3306 # the default port, without this line, you can add or modify another port manually ... ignore other configuration items display # If you remember to adjust the configuration file restart the service service mysqld restart
Fifth, set the root password
# 1. Turn on password-free support # No password to access different versions of mysql console methods may differ, provides two ways here: # the first method: Add a skip-grant-tables in the configuration file, the configuration file something like this: [mysqld] port=3306 skip-grant-tables ... other configuration items # Restart Service service mysqld restart # The second method: mysqld_safe --skip-grant-table & # 2. Enter the mysql command mysql to go directly to the console mysql # 3. Go to mysql database mysql> use mysql; Database changed 4. Modify the root password # 123456, pay attention to the old version may be password field instead of authentication_string, means the same as changing field can be updated mysql> update user set authentication_string = password('123456') where user = 'root'; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 # 5. Update Authorization mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) # 6. recovery password restrictions # If the first method is used to enter the console, just you need to skip-grant-tables added to the configuration file removed vim /etc/my.cnf Delete skip-grant-tables # If you are using the second method to enter the console, kill mysqld_safe and mysqld process # 7. Restart Service service mysqld restart
Sixth, re-login Test
mysql -u root -p