Install mysql8 under centos server

1. Configure yum source

Note: If you think the official rmp download is slow, then jump to the link Domestic source installation method: add link description

1. Download the mysql source installation package
Download the YUM source rpm installation package from the MySQL official website: domestic source installation method, click to enter

复制下载链接:https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

The download directory this time is: /home/directory, so enter: cd /home

Execute the download command:

wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

2. Install the mysql source
After the download is complete, use the following command to install the source:

yum localinstall mysql80-community-release-el7-1.noarch.rpm

3. Check whether the installation is successful

yum repolist enabled | grep "mysql.*-community.*"

Two, install mysql

Just use the command: yum install mysql-community-server.

3. Start the mysql service

1.启动
systemctl start mysqld
或者
service mysqld start
2.查看启动状态
systemctl status mysqld
或者
service mysqld status
3.设置开机启动
systemctl enable mysqld
systemctl daemon-reload

4. Configuration and some commands

1.修改登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

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

Local MySQL client login

mysql -uroot -p

The password is queried in the previous step. Enter and press Enter.

Then change the password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'TestBicon@123';
或者

set password for 'root'@'localhost'=password('TestBicon@123');

Note: mysql5.7 installs the password security check plug-in (validate_password) by default. The default password check policy requires that the password must contain: uppercase and lowercase letters, numbers and special symbols, and the length should not be less than 8 characters. Otherwise, it will prompt ERROR 1819 (HY000): Your password does not satisfy the current policy requirements error, as shown in the figure below:

Through the msyql environment variable, you can view the relevant information of the password policy (to perform this step, you need to modify the default password first, that is, after performing the modification in the previous step, otherwise an error will be reported: ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.):

show variables like '%password%';
validate_password_policy:密码策略,默认为MEDIUM策略

validate_password_dictionary_file:密码策略文件,策略为STRONG才需要

validate_password_length:密码最少长度

validate_password_mixed_case_count:大小写字符长度,至少1个

validate_password_number_count :数字至少1个

validate_password_special_char_count:特殊字符至少1个

The above parameters are password checking rules for the default policy MEDIUM.

To modify the password policy:

在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略:
选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件。
validate_password_policy=0

If you do not need a password policy, add the following configuration to disable it in the my.cnf file:

validate_password = off

Restart the mysql service to make the configuration take effect:systemctl restart mysqld

2. Add a 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.

Modify the remote access permissions of the root user:

Select the mysql database:

use mysql;

View the relevant information of the current root user in the user table of the mysql database:

select host, user from user;

Check the host of the root user in the table. The default localhost should be displayed, which only supports local access and does not allow remote access.

Grant all privileges to the root user and set up remote access

GRANT ALL ON *.* TO 'root'@'%';

If an error is reported:ERROR 1410 (42000): You are not allowed to create a user with GRANT

then use:

update user set host='%' where user ='root';

Then use the following command to make the changes take effect:

flush privileges;

If it is necessary to execute the command that authorized the error before, it will succeed, and finally use the flush privileges; command to refresh.

3. A 2058 exception occurs when the sqlyog link
is completed. When the above configuration is used, a 2058 exception occurs when the sqlyog link is used. At this time, we need to modify mysql, log in to mysql from the command line (same as logging in to modify the password, use the modified password), and then execute The following command:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Where password is the password you modified. Then reconnect in SQLyog, then the connection is successful, OK.

If an error is reported: ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'use the following command:

ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘password’;

4. Modify the default encoding method.
mysql8.0The default encoding method is utf8mb4, so it does not need to be modified when using it. You can use the following command to view it:

SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';

If you need to modify other encoding methods, there are many methods, the following are just examples.

For example, if you need to change it to utf8mb4, you can use the following method:

Modify mysqlthe configuration filemy.cnf(windows为my.ini)

my.cnfGenerally in etc/mysql/my.cnflocation. After finding it, please add the following content in the following three parts:

[client]

default-character-set = utf8mb4

[mysql]

default-character-set = utf8mb4

[mysqld]

character-set-client-handshake = FALSE

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

init_connect='SET NAMES utf8mb4'

Just restart mysql.

collation_connection 、collation_database 、collation_serveIt doesn't matter what r is. But must ensure that the following variables must be utf8mb4. :

character_set_client(Character set used by client source data)
character_set_connection(Connection layer character set)
character_set_database(Default character set of the currently selected database)
character_set_results(Query result character set)
character_set_server(Default internal operation character set)

Among the database connection parameters:

characterEncoding=utf8It will be automatically recognized as utf8mb4, or you can not add this parameter, it will be automatically detected.

butautoReconnect=true must be added.

5. Partial parameter configuration query command
#Query mysqlthe maximum number of connections setting

show global variables like 'max_conn%';
SELECT @@MAX_CONNECTIONS AS 'Max Connections';

Check the maximum number of links

show global status like 'Max_used_connections';

Check whether the slow query log is enabled and the log location

show variables like 'slow_query%';

Check the slow query log timeout record time

show variables like 'long_query_time';

See how many links were created and are linking now

show status like 'Threads%';

View database current links

show processlist;

View database configuration

show variables like '%quer%';

**

Five, completely uninstall mysql

**
1. Uninstall the software

yum remove mysql-community-server

After completion, use rpm -qa|grep mysqthe l command to view, if there is a query result, use yum remove name to clean it up. As shown in the picture:

Then use the command rpm -qa | grep -i mysqlto view, if there is a result, use rpm -e 名称uninstall. For example:

2. Delete files

rm -rf /var/lib/mysql
rm /etc/my.cnf
rm -rf /usr/share/mysql-8.0

If you need to reinstall, you can grant permissions to the mysql directory before the installation is complete to prevent exceptions:

chmod -R 777 /var/lib/mysql

Guess you like

Origin blog.csdn.net/weixin_41675375/article/details/107758294