install mysql
CentOS7 installs mariadb database by default, remove mariadb before installing mysql
yum remove mariadb-libs.x86_64
Download Mysql source
https://dev.mysql.com/downloads/repo/yum/
installation source
yum localinstall mysql57-community-release-el7-11.noarch.rpm
Install community edition mysql
yum install mysql-community-server
start mysql
service mysqld start
View default password
cat /var/log/mysqld.log | grep "password"
Connect mysql with default password for the first time
mysql -uroot -p
If you don't change the default password, you can't use some functions of mysql, so let's change the default password. By default, mysql sets the password to be a mixture of letters + numbers + characters. If you want to set a simple password such as: 123456, it will report the error Your password does not satisfy the current policy requirements . If we must set a simple password, we must modify two global parameters of mysql.
set global validate_password_policy=0;
set global validate_password_length=1;
set new password
set password = password('123456');
ps: This function can only be used when the password is changed for the first time.
open remote link
Select the mysql database, modify the Host field of user='root' in the user table, and change from the original localhost to %, which means that all ips are allowed to log in with the root account.
use mysql;
update user set Host='%' where Host = 'localhost' and user='root';
Restart the mysql service
service mysqld restart
Start genelog service
- Set the file storage address of the log
set global general_log_file="/tmp/general.log";
- enable genelog
set global general_log=on;
- close genelog
set global general_log=off;
New user and authorization
new user
create user 'test'@'%' identified by '123456';
% means that all IPs can be connected remotely. If the error Your password does not satisfy the current policy requirements is reported, execute the two commands **set global validate_password_policy=0; and set global validate_password_length=1;**
Authorize
grant all privileges on *.* to 'test'@'%' identified by '123456' with grant option
Grant all permissions on all tables in all libraries to user test.
grant select privileges on mysql.user to 'test'@'%' identified by '123456' with grant option;
Grant the query permission of the user table of the mysql library to the user test (others include update, insert, delete permissions)
revoke all privileges on *.* from test;
Delete all permissions of all tables in all libraries of user test. If some permissions are appended, they should also be appended and deleted. For example revoke select on mysql.user from test;
Forgot password
Sometimes we forget the root password of mysql. At this time, the following method can be used to easily reset the password without reinstalling mysql.
Enter the mysql configuration file
vim /etc/my.cnf
add a line at the end
skip-grant-tables
Save the configuration file and restart the mysql service
service mysqld restart
At this time, you can log in to mysql without a password
mysql -uroot -p
Enter the mysql library to execute the sql that sets the password
use mysql
update user set authentication_string = password('456789') where user = 'root';
Finally, remove the skip-grant-tables of the configuration file and restart the mysql service.