环境配置

操作系统 :CentOS 7.5 64位
mysql版本:8.0.13

 

步骤

1.卸载系统自带的mariadb-lib

查看mariadb版本
rpm -qa | grep mariadb
卸载mariadb
rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
rpm -qa|grep -i mysql
停止mysql服务,删除mysql
1. rpm -ev #上述结果
注意:可能会抛依赖错误错 error:Failed dependencies:

,则加上 --nodeps不检查依赖关系删除,命令如下

rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64

2. find / -name mysql

3.rm -rf 上述结果

4.mysql 配置文件还要手动删除

rm -rf /etc/my.cnf

5.检查一遍mysql 是否成功删除

        rpm -qa|grep -i mysql

 

2.重启机器


reboot

3.从网易镜像下载mysql安装包

wget https://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

从网易镜像下载mysql安装包

wget https://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

4.解压mysql安装包

tar -xvf mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

5.按顺序安装

必须安装(注意顺序)
rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
非必要安装(注意顺序)
rpm -ivh mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.13-1.el7.x86_64.rpm

6.出现问题

 

 

出现问题:
error:
Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64 libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64 libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64
解决办法:
yum install numactl
出现问题:
error:
Failed dependencies:
pkgconfig(openssl) is needed by mysql-community-devel-8.0.13-1.el7.x86_64
解决办法:
yum install openssl-devel.x86_64 openssl.x86_64 -y
出现问题:
error:
Failed dependencies:
perl(Data::Dumper) is needed by mysql-community-test-8.0.13-1.el7.x86_64
解决办法:
yum -y install autoconf
出现问题:
error:
Failed dependencies:
perl(JSON) is needed by mysql-community-test-8.0.13-1.el7.x86_64
解决办法:
yum install perl.x86_64 perl-devel.x86_64 -y
yum install perl-JSON.noarch -y

如果最后一步还是报错

是缺少libaio库:wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
然后安装该库: rpm -ivh http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
然后yum 安装 net-tools* 库

6.初始化数据库

mysqld --initialize --console

7.目录授权,否则启动失败

chown -R mysql:mysql /var/lib/mysql/

8.启动msyql服务

systemctl start mysqld

9.查看msyql服务的状态

service mysqld status

10.在/var/log/mysqld.log下查看临时密码

cat /var/log/mysqld.log

11.用临时密码登录到数据库

mysql -u root -p3213;

12.执行下列mysql命令 修改密码


alter USER 'root'@'localhost' IDENTIFIED BY '新密码(必须包含:数字大小写字母特殊字符)';

 13.依次执行下列mysql命令

授权远程连接

查看所有用户是否可以远程连接,依次执行下列命令:
show databases;
use mysql;
select host, user, authentication_string, plugin from user;

修改root用户host值,使root用户可以远程登录

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

 flush privileges;

 .使用mysql客户端登录数据库报错如下图

 

mysql -u root -p+ 回车键+输入root用户的密码 登录 ;
show databases;
use mysql;
alter USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root用户的密码';
flush privileges;

#

备注:
mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password。
解决问题方法有两种:
方法1.升级navicat驱动;
方法2.把mysql用户登录密码加密规则还原成mysql_native_password.。
此处我使用的是方法2。


.创建用户和授权

用户创建:
create user 'quanran'@'%' identified by 'QuanRan123:';
授权:
grant all privileges on *.* to 'quanran'@'%' with grant option;
查看用户权限:
select host, user, authentication_string, plugin from user;

备注

备注:
1.创建用户
命令:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
说明:
username: 你将创建的用户名
host: 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%
password: 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器
例子:
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'quanran'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'quanran'@'%' IDENTIFIED BY '123456';
CREATE USER 'quanran'@'%' IDENTIFIED BY '';
CREATE USER 'quanran'@'%';
2.授权
命令:
GRANT privileges ON databasename.tablename TO 'username'@'host'
说明:
privileges:用户的操作权限,如SELECT,INSERT,UPDATE等,如果要授予所的权限则使用ALL
databasename:数据库名
tablename:表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示,如.*
例子:
GRANT SELECT, INSERT ON test.user TO 'quanran'@'%';
GRANT ALL ON *.* TO 'quanran'@'%';
GRANT ALL ON maindataplus.* TO 'quanran'@'%';
注意:
用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
3.设置与更改用户密码
命令:
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
如果是当前登陆用户用:
SET PASSWORD = PASSWORD("newpassword");
例子:
SET PASSWORD FOR 'quanran'@'%' = PASSWORD("123456");
4.撤销用户权限
命令:
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
说明:
privilege, databasename, tablename:同授权部分
例子:
REVOKE SELECT ON *.* FROM 'quanran'@'%';
注意:
1.如果用 GRANT SELECT ON test.user TO 'quanran'@'%' 给用户’quanran’@’%‘授权,则使用 REVOKE SELECT ON . FROM 'quanran'@'%'; 并不能撤销该用户对test数据库中user表的SELECT 操作。
2.如果用 GRANT SELECT ON . TO 'quanran'@'%'; 给’quanran’@’%'授权,则使用 REVOKE SELECT ON test.user FROM 'quanran'@'%'; 命令也不能撤销该用户对test数据库中user表的Select权限。
3.具体信息可以用命令SHOW GRANTS FOR 'quanran'@'%'; 查看。
5.删除用户
命令:
DROP USER 'username'@'host';

 

posted on 2019-08-24 11:14  谢Rain  阅读(452)  评论(0编辑  收藏  举报