1. There is no MySQL source in the yum repository, download the source first
1. Download the mysql source
//5.6地址
shell> wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
The latest version can be downloaded from the official website https://dev.mysql.com/downloads/repo/yum/
2. Install the downloaded rpm package
shell> sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
3. Check whether the mysql source is installed successfully
shell> yum repolist enabled | grep "mysql.*-community.*"
The installation is successful as follows
2. Install MySQL
When using the mysql yum repository, the latest version is selected for installation by default, or a version can be selected for installation by manually editing the file. For example, to install mysql5.6 version, set enabled=1 for mysql56-community, and enable=0 for mysql57-community.
vim /etc/yum.repos.d/mysql-community.repo
Install:
shell> yum install mysql-community-server
3. Start the MySQL service
shell> systemctl start mysqld
4. View MySQL service status
shell> systemctl status mysqld
5. Set to boot
shell> systemctl enable mysqld
shell> systemctl daemon-reload
6. Reset the local password
shell> mysql -u root
This error may be reported when logging in: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2), the reason is /var/lib/mysql Access rights issues. The following command changes the owner of /var/lib/mysql to the current user:
shell> sudo chown -R root:root /var/lib/mysql
Restart the MySQL service systemctl restart mysqld
to continue resetting the password
shell> mysql -u root //直接回车进入mysql控制台
mysql> set password for 'root'@'localhost'=password('Root123456'); //设置密码
mysql> exit //退出
shell> systemctl restart mysqld //重启服务
7. Add remote login user
By default, only the root account is allowed to log in locally. If you want to connect to mysql on other machines, you must modify root to allow remote connections, or add an account that allows remote connections. For security, I add a new account:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yanglei'@'%' IDENTIFIED BY 'yanglei1994!' WITH GRANT OPTION;
8. Delete
1. Uninstall
shell> yum remove mysql mysql-server mysql-libs compat-mysql51
shell> rm -rf /var/lib/mysql
2. Check if there are other mysql, such as yum remove + [name] to delete
shell> rpm -qa|grep mysql
3. Check and delete other related files
an examination
shell> find / -name mysql
delete
shell> rm -rf /usr/lib/mysql
9. Reset password
1. Modify MySQL login settings:
shell> vim /etc/my.cnf
Press a to add skip-grant-tables
press esc then :x to save and exit
2. Restart the mysql service
shell> systemctl restart mysqld
3. Change the password of the root user
update mysql.user set authentication_string=password("PASSWORD") where user="root";
flush privileges;
4. Delete and restart the service added in the first step
5. Enter mysqlmysql -u root
6. Set password
//设置密码强度和长度
> set global validate_password_policy=0;
> set global validate_password_length=1;
// 更改密码
> alter user 'root'@'localhost' identified by 'PASSWORD';
7. If you set the root user to be able to access remotely, you also need to execute:
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
> flush privileges;