CentOS7 yum mounted remote connection MySQL5.7 +

 

1 Download and install the MySQL official Yum Repository

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

  Using the above command directly download the installation of Yum Repository, looks about 25KB, and then you can directly install yum.

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

  Then began installing MySQL server.

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

  This step may take some time, it will overwrite mariadb before the installation is complete.

At this point MySQL installation is complete, then some set of MySQL.

2 MySQL database settings

  First start MySQL

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

  View MySQL running, running state is shown:

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

  At this time, MySQL has started running, but in order to enter at this time MySQL had to first find out the root user password, you can find the password in the log file with the following command:

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

  The following command into the database:

[root@localhost ~]# mysql -uroot -p

  Enter the initial password, this time can not do anything, because the default MySQL database to operate after the password must be changed:

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

  There is a problem, when setting a new password if set too simple will complain:

  The reason is because there are norms MySQL password settings, specifically related to the value validate_password_policy:

 

  MySQL complete the initial password rules can be viewed with the following command:

复制代码
复制代码
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 4     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
复制代码
复制代码

  密码的长度是由validate_password_length决定的,而validate_password_length的计算公式是:

validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)

 

我的是已经修改过的,初始情况下第一个的值是ON,validate_password_length是8。可以通过如下命令修改:

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

  设置之后就是我上面查出来的那几个值了,此时密码就可以设置的很简单,例如1234之类的。到此数据库的密码设置就完成了。

  但此时还有一个问题,就是因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:

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

  此时安装才算真的完成了。

开启多ip访问(默认只许本机访问 localhost)

输入密码(密码输入是不显示的)

mysql -uroot -p

 

 

 

切换数据库:

use mysql;

 

 

 查询数据库内容(host字段中,localhost表示只允许本机访问,要实现远程连接,可以将root用户的host改为%,%表示允许任意host访问,如果需要设置只允许特定ip访问,则应改为对应的ip。)

select user,host from user;

 

 修改root用户的host字段

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

 

 此时修改好了记得刷新

flush privileges

 

 测试连接:

 

Guess you like

Origin www.cnblogs.com/gu-bin/p/12417316.html