Linux-Mysql8安装手册:
环境说明:
操作系统:SuSE Linux
Mysql:mysql-8.0.11
基本命令:
启动: service mysql start/restart
停止: service mysql stop
查看状态: service mysql status
下载mysql8安装包:
mysql-8.0.11-1.sles12.x86_64.rpm-bundle.tar
安装流程:
1.卸载系统自带的mysql版本:
1.1 停止mysql:
service mysql stop
1.2 查看已安装的mysql依赖:
rpm -qa | grep -i mysql
1.3 卸载安装包:rpm –ev XXX
按顺序删除所有上述出现的结果:
mysql-community-server
mysql-community-client
mysql-community-devel
mysql-community-libs
mysql-community-common
1.4 再次检查,如果无结果则表示卸载成功:
rpm -qa | grep -i mysql
1.5 检查与数据库相关的文件,彻底删除:(快照类型的可不删)
find / -name mysql
rm –rf
如:
/usr/include/mysql
/usr/include/mysql/mysql
/usr/lib64/mysql
/usr/bin/mysql
/var/lib/mysql
/var/log/mysql
2.按顺序安装mysql安装包:
2.1 安装过程:
2.1.1 必要安装(注意安装顺序):
rpm –ivh mysql-community-common-8.0.11-1.sles12.x86_64.rpm
rpm –ivh mysql-community-libs-8.0.11-1.sles12.x86_64.rpm
rpm –ivh mysql-community-client-8.0.11-1.sles12.x86_64.rpm
rpm –ivh mysql-community-server-8.0.11-1.sles12.x86_64.rpm
2.1.2 非必要安装(注意安装顺序):
rpm –ivh mysql-community-devel-8.0.11-1.sles12.x86_64.rpm
rpm –ivh mysql-community-test-8.0.11-1.sles12.x86_64.rpm
3.修改密码:
3.1 刚刚启动成功之后,用命令查看默认密码并且登录:
(1)查看:cat /var/log/mysqld.log | grep password
(2)登陆:mysql -u root -p
(3)输入密码
(4)修改密码:
set global validate_password.policy=0;
set global validate_password.length=1;
ALTER USER "root"@"localhost" IDENTIFIED BY "1234"; // 新密码为1234
(这里我们如果需要连接外网,改密码的方式需要更换: ALTER USER "root"@"%" IDENTIFIED BY "1234";)
(5)exit退出
(6)mysql -u root -p 回车+密码
3.2 授权远程访问:
3.2.1 首先确保关闭了防火墙并重启mysql:
(1)SUSeLinux关闭防火墙:service SuSEfirewall2 stop
(2)重启mysql:service mysql restart
(2)选择数据库:use mysql
(4)查看表:show tables
3.2.2 修改连接规则:
(1)查看规则:select host,user from user \G;
(2)修改规则:update user set host= '%' where user = 'root';
(3)所以需要更改加密方式——版本变动:
update user set plugin='mysql_native_password' where user ='root';
(4)刷新权限:
flush privileges;
(5)测试外网连接mysql服务器:
(如果外网连接失败的话,先按照【重置密码】执行一遍,再执行【修改密码】, ALTER USER "root"@"%" IDENTIFIED BY "1234"; 修改完之后再次连接服务器)
4.重置密码:
开启免密码登陆,修改my.cnf文件:
默认在/etc/my.cnf中:vim /etc/my.cnf
在[mysql]模块下面添加:skip-grant-tables
保存退出:!wq
(2)重启服务,使配置生效:
service mysqld restart
(3)登陆:
mysql -u root -p //不输入密码直接敲回车键
(4)选择数据库
use mysql:把密码置空(因为免密登陆时不能直接修改密码)
update user set authentication_string = '' where user = 'root';
(5)退出
quit
(6)在/etc/my.cnf下删掉skip-grant-tables,并重启服务:
service mysqld restart
(7)登陆:
mysql -u root -p //直接敲回车键,因为已置空密码
(8)重复[修改密码]步骤