This is the 14th day of my participation in the August More Text Challenge. For details, see: August More Text Challenge
Using YUM to install MySQL is the easiest way to install MySQL. However, there are many problems when using the compressed package. Using YUM to install MySQL is simple and quick.
MySQL is installed on the Linux operating system
1. Check whether MySQL has been installed using yum
Using the command: RPM – qa | grep -i mysql
- The following figure shows the installed modules. Uninstall them first and then reinstall them
Yum -y remove < full name >
: Uninstalls related modules- If the uninstallation fails, run the following command:
RPM -er < full name >
- If nothing changes after the installation, the installation is not complete
2. Use the yum command to download and install MySQL related services
/usr/localcd/ usr/local # download. The RPM file wget HTTP: / / http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8# yum --install root=/usr/local/mysql --releaserver=/ -y install mysql-serverCopy the code
- Wait until all service modules are installed
3. MySQL configuration file
- Configuration file:
/etc/my.cnf
- Log file:
/var/log/mysqld.log
- Service startup script:
/usr/lib/systemd/system/mysqld.service
- The socket file:
/var/run/mysqld/mysqld.pid
- Add mysql configuration content:
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock server_id = 1 expire_logs_days = 3 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid Copy the code
4. MySQL service commands
systemctl start mysqld.service
: Starts the mysql servicesystemctl status mysqld.service
Mysql > Check mysql service status,- -l: displays detailed status information
systemctl stop mysql.service
: Stop the mysql servicesystemctl restart mysql.service
: Restart the mysql servicesystemctl enable mysqld
: Set mysql to automatically start upon startupsystemctl daemon-reload
: Starts as a daemon process
5. Change the MySQl password
View randomly generated passwords
After mysql is installed, a random password is generated in the corresponding log file. You can run the following command to view the password:
cat /var/log/mysqld.log
: View all log filesGrep "password"/var/log/mysqld log
: Matches the password keyword in the log file
Skip password authentication
If the login fails with a random password, skip the authentication phase and use SQL statements to update the password after the login
vi /etc/my.cnf
: Modify the configuration file and addskip-grant-tables
Then save the Settings and exit, indicating that the login is not authenticated- Restart the mysql service and log in to the mysql client using mysql
Use SQL statements to change the login password
mysql -u root -p
: Run the following command to log in to mysql: Enter the password in the log file to log in to mysqlALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxxx';
Change the password of user root to XXXXXXXX- The default password policy requires the password to be a combination of uppercase and lowercase letters, digits, and special characters and contain at least eight characters
6. Allow remote login
Set to allow remote connections from other ends and navicate.
Connect to the client
mysql -u root -p Root@2020
mysql> use mysql;
mysql> ALTER USER 'root'@The '%' IDENTIFIED WITH mysql_native_password BY 'Root@2021';
If the previous sentence failed, use the following command
#mysql> grant all on *.* to root@"%" identified by "Root@2021";
mysql> flush privileges;
Copy the code