2.CentOS7.6安装mysql5.7

2020-06-13  本文已影响0人  吃饱喝足搬代码丶

1.在官网https://dev.mysql.com/downloads/mysql/上下载并安装rpm包:

官网下载
#解压: 
tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar 

#按顺序安装: 
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm 
rpm -ivh mysql-community-devel-5.7.21-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
若报下图错:
缺失相关依赖包
则解决方法为:
yum install libaio net-tools -y

2.启动并查看数据库:

systemctl start mysqld.service #启动数据库服务
systemctl enable mysqld   #设置开机自启动
systemctl status mysqld.service  #查看数据库状态

3.查看密码并登录:

grep "password" /var/log/mysqld.log 
mysql -u root -p 
(输入查出的初始密码进行登录)
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; #登录后修改密码
若提示密码过于简单:
密码过于简单
解决方法:
#通过如下命令可以查看初始密码规则:

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)

#可通过如下命令修改:
mysql> set global validate_password_policy=0; 
mysql> set global validate_password_length=1;

4.因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉(注:用yum源安装的情况下才需要):

yum -y remove mysql57-community-release-el7-10.noarch
忘记密码的情况下:
vi /etc/my.cnf  #添加如下语句: 
skip-grant-tables
修改mysql配置
systemctl restart mysqld.service  #重启
mysql -uroot -p 
(直接点击回车即可登录) 
use mysql; 
update user set authentication_string=password('123456') where user='root';  #修改密码
flush privileges; 
exit;
vi /etc/my.cnf  #注释跳过登录配置:
#skip-grant-tables 

systemctl restart mysqld.service #重启
远程登录遇到1103错误,解决:

1.改表法:

原因:可能是系统数据库mysql中user表中的host是localhost的原因, 所以修改这个值为自己服务器的ip即可: 
mysql -u root -p 
use mysql; #选择mysql库 
select 'host' from user where user='root';#查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称) 
update user set host = '%' where user ='root';#修改host值(通配符%表示任意主机/IP地址),当然也可以直接增加IP地址 
flush privileges; #刷新MySQL的系统权限相关表 
select 'host'   from user where user='root';

2.授权法:

#你想myuser使用mypassword从任何主机连接到mysql服务器的话。 
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 

#如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.0.1' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
这期间遇到的问题:
需要修改用户密码

解决:

set global validate_password_length=6; 
set global validate_password_policy=0; 
alter user user() identified by "123456";
修改相关配置
上一篇下一篇

猜你喜欢

热点阅读