Install and configure MySQL 5.7 and centosmysql in CentOS 7
Test environment:
CentOS 7 64-bit Minimal MySQL 5.7
Configure yum Source
Locate the yum source rpm installation package in the https://dev.mysql.com/downloads/repo/yum/
Rpm installation package
Install mysql Source
# Download shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm# install mysql source shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm
Run the following command to check whether the mysql source is successfully installed:
shell> yum repolist enabled | grep "mysql.*-community.*"
Mysql source installed successfully
Install MySQL
Use the yum install command to install
shell> yum install mysql-community-server
Start MySQL Service
In CentOS 7, the new command for starting/disabling services is systemctl start | stop
shell> systemctl start mysqld
Use systemctl status to view MySQL status
shell> systemctl status mysqld
MySQL startup status
Set startup
shell> systemctl enable mysqld shell> systemctl daemon-reload
Modify the root Local Account Password
After mysql is installed, the generated default password is in the/var/log/mysqld. log file. Use the grep command to find the password in the log.
shell> grep 'temporary password' /var/log/mysqld.log
View temporary password
After logging on with the initial password for the first time, run the following command to change the password:
shell> mysql -uroot -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Or
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
Later, use the update set statement to change the password.
mysql> use mysql; mysql> update user set password=PASSWORD('MyNewPass5!') where user='root';
Note: The password security check plug-in (validate_password) is installed by default in mysql 5.7. The default password check policy requires that the password must contain uppercase and lowercase letters, numbers, and special characters, and the length cannot be less than 8 characters. Otherwise, ERROR 1819 (HY000): Your password does not satisfy the current policy requirements is returned. View detailed password policies on the MySQL website
Add Remote Login User
By default, only the root account is allowed to log on locally. To connect to mysql on other machines, you must add an account that allows remote connection. OrChange root to allow remote connection(Not recommended)
Add an account that allows remote connection
mysql> GRANT ALL PRIVILEGES ON *.* TO 'zhangsan'@'%' IDENTIFIED BY 'Zhangsan2018!' WITH GRANT OPTION;
Change root to allow remote connection(Not recommended)
mysql> use mysql; mysql> UPDATE user SET Host='%' WHERE User='root'; mysql> flush privileges;
Set the default encoding to utf8.
Mysql does not support Chinese characters by default after installation. You need to modify the encoding.
Modify the/etc/my. cnf configuration file and add the encoding configuration under the relevant node (if not, add it as needed), as shown below:
Copy codeThe Code is as follows:
[Mysqld]
Character-set-server = utf8
[Client]
Default-character-set = utf8
[Mysql]
Default-character-set = utf8
Restart the mysql service to query the encoding. We can see that it has been changed.
shell> systemctl restart mysqld shell> mysql -uroot -p mysql> show variables like 'character%';
View the default encoding configuration file path:
Configuration File:/etc/my. cnf
Log File:/var/log/mysqld. log
Service Startup Script:/usr/lib/systemd/system/mysqld. service
Socket file:/var/run/mysqld. pid