环境配置
操作系统 :CentOS 7.5 64位
mysql版本:8.0.13
步骤
1.卸载系统自带的mariadb-lib
查看mariadb版本rpm -qa | grep mariadb卸载mariadbrpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
rpm -qa|grep -i mysql停止mysql服务,删除mysql1. rpm -ev #上述结果注意:可能会抛依赖错误错 error:Failed dependencies:,则加上 --nodeps不检查依赖关系删除,命令如下rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_642. find / -name mysql3.rm -rf 上述结果4.mysql 配置文件还要手动删除rm -rf /etc/my.cnf5.检查一遍mysql 是否成功删除 rpm -qa|grep -i mysql
2.重启机器
reboot3.从网易镜像下载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.rpmrpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpmrpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpmrpm -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.rpmrpm -ivh mysql-community-embedded-compat-8.0.13-1.el7.x86_64.rpmrpm -ivh mysql-community-devel-8.0.13-1.el7.x86_64.rpmrpm -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 -yyum 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等,如果要授予所的权限则使用ALLdatabasename:数据库名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';