CentOS7 Installation\Uninstall MySQL

1. Download and install MySQL's official Yum Repository

[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

Install MySQL Server

root@localhost ~]# yum -y install mysql-community-server

2. MySQL database settings

Start MySQL

[root@localhost ~]# systemctl start  mysqld.service

View MySQL running status

[root@localhost ~]# systemctl status mysqld.service

MySQL is now working properly and needs to find the root password

[root@localhost ~]# grep "password" /var/log/mysqld.log

Log in to mysql with the following command

# mysql -uroot -p

Enter the initial password, and nothing can be done at this time because MYSQL must change the password by default to work properly

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

# There's a problem here, too simple to set a new password will cause an error

The complete initial password rules can be viewed with the following commands

mysql>show variables like 'validate_password';

You can modify it with the following commands

mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

Another problem is the Yum Repository, which will be updated automatically every time a yum operation happens in the future and needs to be uninstalled

[root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch

The following error message occurred in the remote login database
ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx',
The reason is that no appropriate permissions have been granted

#Any Host
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

#Specify Host
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@'10.10.50.127' IDENTIFIED BY '654321' WITH GRANT OPTION;

# Then refresh permissions
mysql>flush privileges;

Modify the total user table of the mysql database so that phase users can log in from a host

mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

The client provides an environment for MYSQL, but does not support Chinese. You can view the character set of MySQL by following commands

mysql>show variables like 'character_set%';

In order for MySQL to support Chinese, you need to change the character set to UTF-8 as follows

# vim /etc/my.cnf
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8

[mysql]
no-auto-rehash
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Restart mysql service

# service mysqld restart

Reviewing database encoding

show variables like 'character_set%';

 

Check to see if MySQL is installed
rpm -qa | grep mysql
Check to see if MySQL service is started and closed
# View mysql service status
service mysqld status

# Close mysql service
service mysqld stop
 
3. Modify the password of the root user
Method 1: Use the SET PASSWORD command 
Log in to MySQL first. 
Format: mysql> set password for username@localhost = password('new password'); 
Example: mysql> set password for root@localhost = password ('123'); 

Method 2: mysqladmin was used 
Format: mysqladmin-u username-p old password new password 
Example: mysqladmin-uroot-p123456 password 123 

Method 3: Edit the user table directly with UPDATE 
Log in to MySQL first. 
mysql> use mysql; 
mysql> update user set password=password('123') where user='root' and host='localhost'; 
mysql> flush privileges; 

Method 4: When you forget the root password, you can do this 
Take windows for example: 
1. Close the running MySQL service. 
2. Open the DOS window and go to the mysql\bin directory. 
3. Enter mysqld --skip-grant-tables to return.--skip-grant-tables means to skip permission table authentication when starting the MySQL service. 
4. Open another DOS window (because the DOS window just now can't be moved) and go to the mysql\bin directory. 
5. Enter Mysql to return, if successful, the MySQL prompt >. 
6. Connect permission database: use mysql;. 
6. Change the password: update user set password=password("123") where user="root"; (don't forget to add the semicolon at the end). 
7. Refresh permissions (required steps): flush privileges;. 
8.Exit quit. 
9. Log off the system and enter again. Log in with the user name root and the new password 123 you just set.

 

 
4. Uninstall the components installed by MySQL

 

Because of dependencies, uninstall in sequence. 
Note that the rpm suffix is installed but not uninstalled.
rpm -ev mysql-community-server-5.7.19-1.el7.x86_64
rpm -ev mysql-community-client-5.7.19-1.el7.x86_64
rpm -ev mysql-community-libs-5.7.19-1.el7.x86_64
rpm -ev mysql-community-common-5.7.19-1.el7.x86_64
Find and delete MySQL related files
#Execution process
[root@localhost ~]# whereis mysql
mysql: /usr/share/mysql
[root@localhost ~]# find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql


#Delete MySQL related files
rm -rf /var/lib/mysql/
rm -rf /usr/share/mysql/

# Delete Log File
rm -rf /var/log/mysqld.log


#Check to see if deleted
rpm -qa | grep mysql
whereis mysql
find / -name mysql

Keywords: Programming MySQL RPM yum Database

Added by tweet on Sun, 26 Apr 2020 19:48:31 +0300