Centos 7 MYSQL5.7 installation and uninstallation

                           Centos 7 MYSQL5.7 installation and uninstallation

One, uninstall the installed MySql

1.1 rpm view installation

rpm -qa | grep -i mysql

1.2 rpm uninstall

Clear the MySQL found above

rpm -e mysql57-community-release-el7-9.noarch
rpm -e mysql-community-server-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64
rpm -e mysql-community-common-5.7.17-1.el7.x86_64
rpm -e mysql-community-client-5.7.17-1.el7.x86_64
cd /var/lib/  
rm -rf mysql/

1.3 Clear remaining items

删除mysql的所有配置
rm –rf /usr/my.cnf
rm -rf /root/.mysql_sercret
 
剩余配置检查
chkconfig --list | grep -i mysql
chkconfig --del mysqld
根据上面的列表,删除 ,如:mysqld

Two, install MySql

2.1 Download Yum source

Now there is no yum source by default on centos, yum installs MariaDB, so we need to configure the yum source first. 

wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'

 

2.2 Install Yum source

rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

  

2.3 Install MySql

yum install -y mysql-community-server

  

2.4 Start mysql

mysql basic configuration instructions (vim /etc/my.cnf)

character-set-server=utf8

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

# 设置时区为东八区
default-time_zone = +8:00
# 密码策略
validate_password_policy=0
validate_password_length=1

# 不区分大小写
lower_case_table_names=1

# 慢查询
slow_query_log=on
long_query_time=3
slow_query_log_file=/var/lib/mysql/VM_0_12_centos-slow.log
log_queries_not_using_indexes=on

# 缓存
query_cache_type=on
query_cache_size=102400

In centos7, there is no service command, but the systemctl command is used.

systemctl start mysqld

Check status

systemctl status mysqld

  

2.5 Login to the database and modify the database password

One of the new features of mysql5.7 is that a custom password will be generated during initialization, and then you need to find this password and enter it when logging in. Note that it is not displayed when entering the password.

倘若没有/var/log/mysqld.log,可以先删除原来安装过的mysql残留的数据
rm -rf /var/lib/mysql
再启动mysql
systemctl start mysqld #启动MySQL

Find the password: The red box is the password:

grep 'temporary password' /var/log/mysqld.log

  

Log in to the database: here, you do not need to enter a password after -p, and enter it after pressing Enter. After changing the password, log in and add the password directly after -p.

Note that if the modified password is too simple, it will not be modified, just add uppercase and lowercase letters and numbers. If you don’t want to set such a complicated password, you can modify the rules:

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

change Password:

SET PASSWORD = PASSWORD('123456');

Set up remote login (it is recommended that root not authorize remote access, please create a new mysql user)

Now it is impossible to log in and access with tools locally. Now we need to do two things, one is to open port 3306 on the cloud server; the other is to configure remote access.

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;

Set the password just now to log in remotely, and then use the flush command to make the configuration take effect immediately. If it still fails, you can try to restart the database.

Other options:

#vim /etc/my.cnf (Note: My.ini is modified under windows)

Search for mysqld in the document and locate the text section [mysqld]. Add "skip-grant-tables" to any line after [mysqld] to skip the password verification process (comment out this line after the modification is completed).

mysql5.7: update user set password=password('123456') where user='root' and host='localhost';

mysql8: update mysql.user set authentication_string='123456' where user='root';


数据库8.0已经没有password这个字段, password字段改成了authentication_string, 所以需要将password改成authentication_string。

2.6 Modify some simple configurations

The MySql configuration file installed by yum is in the /etc folder by default:

vim /etc/my.cnf

Add under [mysqld] without semicolon.
Character set: Note that it is utf8 instead of utf-8!

character-set-server=utf8

At this time, use show variables like'char%'; you can see that the character set is utf8.
SQL supports the group by statement

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Set the time zone to Dongba District

default-time_zone = '+8:00'

Finally, restart the database to make the configuration effective.

systemctl restart mysqld

Other configuration


# 不区分大小写
lower_case_table_names=1

#慢查询
slow_query_log=on
long_query_time=3
slow_query_log_file=/var/lib/mysql/VM_0_12_centos-slow.log
log_queries_not_using_indexes=on

# 缓存
query_cache_type=on
query_cache_size=102400

Slow query basic configuration

  1. slow_query_log Start stop technology slow query log
  2. slow_query_log_file specifies the storage path and file of the slow query log (the default is to put it together with the data file)
  3. long_query_time specifies the SQL execution time to record the slow query log (unit: second, default 10 seconds)
  4. log_queries_not_using_indexes Whether to log SQL without indexes
  5. log_output The location where the log is stored [TABLE] [FILE] [FILE, TABLE]

Slow query analysis

        There are a lot of slow query log records. It is not easy to find a slow query log from it. Generally speaking, some tools are needed to quickly locate the SQL statement that needs to be optimized. Two slow query auxiliary tools are introduced below.

Mysqldumpslow(pt_query_digest)

The commonly used slow query log analysis tool summarizes the same SQL except for the query conditions, and outputs the analysis results in the order specified in the parameters.

grammar:

mysqldumpslow -s r -t 10 slow-mysql.log

-s order (c,t,l,r,at,al,ar)

         c: total times

         t: total time

         l: lock time

         r: total data row

         at,al,ar: average number of t,l,r [for example: at = total time/total number of times]

  -t top specifies to take the previous few days as the result output

mysqldumpslow -s r -t 10 /var/lib/mysql/VM_0_12_centos-slow.log

 

User rights

Create an ordinary user and authorize
GRANT ALL PRIVILEGES ON *.* TO'myuser'@'%' IDENTIFIED BY'mypassword' WITH GRANT OPTION;
Authorization: grant all on *.* to oyc@'%' identified by '123456';

Above, all means all permissions (such as read, write, query, delete, etc.);.
There are two *, the first * means all databases, and the back * means all tables;

Identified by is followed by the password, enclosed in single quotes, where user1 refers to user1 on localhost.
Authorize a user on other machines on the network:
grant all on oyc1.* to'oyc1'@'192.168.33.128' identified by '111222';
above, the IP of the user and the host are enclosed in single quotes, one of the two There is an @ symbol between them, and the IP can be replaced by% to indicate all hosts.

View MySQL user permissions

    View current user (own) permissions:
    show grants;
    View other MySQL user permissions:
    show grants for oyc@localhost;

Revoke the permissions granted to the MySQL user.

The syntax of revoke is similar to grant, just change the keyword "to" to "from":
grant all ON oyc1.* to'oyc1'@'%';
revoke all on oyc1.* from'oyc1'@' %';

Mysql installation location

//(show variables  like "character_sets_dir%")

character_sets_dir :  /usr/share/mysql/charsets/

2.7 Set boot up

systemctl enable mysqld
systemctl daemon-reload

 

Guess you like

Origin blog.csdn.net/u014553029/article/details/101126897