# 下载mysql
$ wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
# 解压
$ mysql
tar
-zxvf mysql-8.0.11-linux-glibc2.12-x86_64.
tar
.gz -C
/usr/local
# 修改文件夹名称
$
mv
mysql-8.0.11-linux-glibc2.12-x86_64/ mysql
添加默认配置文件
$ vim
/etc/my
.cnf
[mysqld]
port=3306
user=mysql
basedir=
/usr/local/mysql
datadir=
/usr/local/mysql/data
# 创建mysql组
$ groupadd mysql
# 创建mysql用户
$
useradd
-g mysql mysql
# 创建mysql数据目录
进入mysql安装目录
$ cd /usr/local/mysql
$
mkdir
data
# 初始化mysql
进入bin文件夹
$ cd bin
$ .
/mysqld
--initialize --user=mysql --basedir=
/usr/local/mysql/
--datadir=
/usr/local/mysql/data/
# 初始化报错
bin
/mysqld
: error
while
loading shared libraries: libaio.so.1: cannot
open
shared object
file
: No such
file
or directory
# 解决方法
yum
install
-y libaio
# 初始化报错
2018-07-08T02:53:24.542370Z 0 [System] [MY-010116]
/usr/local/mysql/bin/mysqld
(mysqld 8.0.4-rc) starting as process 17745 ...
mysqld: Can
't create/write to file '
/tmp/mysql/data/ibd35qXQ
' (Errcode: 13 - Permission denied)
2018-07-08T02:53:24.554816Z 1 [ERROR] [MY-011066] InnoDB: Unable to create temporary
file
; errno: 13
2018-07-08T02:53:24.554856Z 1 [ERROR] [MY-011066] InnoDB: InnoDB Database creation was aborted with error Generic error. You may need to delete the ibdata1
file
before trying to start up again.
2018-07-08T02:53:24.555000Z 0 [ERROR] [MY-010020] Data Dictionary initialization failed.
2018-07-08T02:53:24.555033Z 0 [ERROR] [MY-010119] Aborting
2018-07-08T02:53:24.555919Z 0 [System] [MY-010910]
/usr/local/mysql/bin/mysqld
: Shutdown complete.
# 解决办法:修改/tmp/mysql的目录权限
$
chown
-R mysql:mysql
/tmp/mysql
# 初始化成功
> 如果无异常情况日志如下可以看到mysql默认会生成root账号和密码root@localhost:
/TI
(mjVAs1Ta
[root@localhost mysql]
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-01-29T10:19:34.023997Z 0 [System] [MY-013169] [Server]
/usr/local/mysql/bin/mysqld
(mysqld 8.0.13) initializing of server
in
progress as process 4240
2019-01-29T10:19:39.764895Z 5 [Note] [MY-010454] [Server] A temporary password is generated
for
root@localhost:
/TI
(mjVAs1Ta
2019-01-29T10:19:43.041419Z 0 [System] [MY-013170] [Server]
/usr/local/mysql/bin/mysqld
(mysqld 8.0.13) initializing of server has completed
# 拷贝mysql启动文件到系统初始化目录
$
cp
/usr/local/mysql/support-files/mysql
.server
/etc/init
.d
/mysqld
# 启动mysql服务器
$ service mysqld start
重置mysql密码
修改my.cnf
[mysqld] 域中添加skip-grant-tables
重启mysql
重新使用空密码登录,直接敲回车
mysql -u root -p
切换数据库,并将密码清空
mysql >use mysql;
mysql >update user set authentication_string = '' where user = 'root';
退出
mysql >quit
删除my.cnf中的skip-grant-tables,并重启服务
systemctl restart mysqld
重新登录root账号,密码直接回车
修改root密码
mysql >ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
设置远程可以访问
登录mysql
可以先查看user表
select user,authentication_string,host from user;
修改root为不限制ip访问
update user set host = '%' where user = 'root';
此时root的host是所有都可以了
然后刷新修改,FLUSH PRIVILEGES;
这步一定要做,否则无法生效
修改加密方式
使用Navicat连接时密码填写正确提示client does not support authention protocol requested。。。。
上网搜索解决方案,网上说出现这种情况的原因是:mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password,
1.登录mysql
2.然后输入
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #修改加密规则 (这行我没有写,不过貌似也可以)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #更新一下用户的密码
FLUSH PRIVILEGES; #刷新权限
3.输入刚刚修改的密码,再次测试连接,可以发现连接成功