centos7.6 安装Mysql5.7

13 篇文章 0 订阅
10 篇文章 0 订阅

添加MySQL Yum库

# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
# rpm -ivh mysql80-community-release-el7-1.noarch.rpm

选择要安装的MySQL版本

# vim /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0  // 将这里的0改为1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1  //将这里的1改为0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

enabled=0为禁用对应版本的YUM库,enabled=1为启用,默认8.0的配置为enabled=1,安装5.7的话,就把8.0的enabled=1修改为enabled=0,然后把5.7的enabled=0修改为enabled=1,修改完成,:wq保存

安装MySQL并启动

# yum install mysql-community-server
# service mysqld start

查看MySQL初始密码

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

如果查询为空则无密码,直接回车即可

修改MySQL初始密码

# mysql -u root -p
> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

给root 权限开启 远程登录

> use mysql;
> select user,host from user;
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

为数据库创建单独的用户并给他单独数据库的所有权限

> create user 'test'@'%' identified by 'CKNiNXZgLk4H2kqYS';
> grant all privileges ON test.* TO 'test'@'%';
> ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY 'CKNiNXZgLk4H2kqYS';

推荐

更改默认3306端口
# vi /etc/my.cnf
添加 port= 端口号 即可
# systemctl restart mysqld

设置MySQL数据库名不区分大小写

# vi /etc/my.cnf
在mysqld里加上
lower_case_table_names=1
# systemctl restart mysqld

ERROR

ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 42. Created with MySQL 50564, now running 50729. Please use mysql_upgrade to fix this error.

# mysql_upgrade -u root -p
# mysql -uroot -p

密码为空直接回车

ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
# vi /etc/my.cnf
skip-grant-tables   // 添加
# service mysqld restart
# mysql -u root -p
> set password for 'root'@'localhost' = password('yourpasswd');
> quit
# vi /etc/my.cnf
skip-grant-tables   // 删除
# service mysqld restart
[Err] 1682 - Native table ‘performance_schema’.‘session_status’ has the wron
# mysql_upgrade -u root -p
> set @@global.show_compatibility_56=ON;

注:从mysql5.7.6开始information_schema.global_status已经开始被舍弃,为了兼容性,此时需要打开 show_compatibility_56

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

查看 mysql 初始的密码策略

SHOW VARIABLES LIKE 'validate_password%';

设置密码的验证强度等级为LOW

set global validate_password_policy=LOW; 

设置密码长度为6

set global validate_password_length=6; 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值