1. 官网下载资源
服务器yum方式太慢了,所以选用tar包解压方式,有压缩和未压缩的两种,大小不一样,我下载的是xz包
解压命令:xz -d abc.tar.xz 解出的tar包继续执行:tar -xvf abc.tar
如提示xz没安装:yum -y install xz
2. 参考文档初始化(参考官方refman8.0-en文档2.2节)
首先执行:
groupadd mysql
useradd -r -g mysql -s /bin/false mysqlcd进入bin文件夹执行初始化程序:mysqld --initialize --user=mysql
如果提示:error while loading shared libraries: libnuma.so.1 ,yum安装下这个库:yum -y install numactl,再执行上面的语句。
正确输出如下(注意记录好临时密码!):
2018-10-18T10:04:57.800365Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-10-18T10:04:57.800572Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.12-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.12) initializing of server in progress as process 3655
2018-10-18T10:05:01.094610Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: SkpVw0jqv?AB
2018-10-18T10:05:03.680974Z 0 [System] [MY-013170] [Server] /usr/local/mysql-8.0.12-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.12) initializing of server has completed
添加服务脚本,可选:cp support-files/mysql.server /etc/init.d/mysql.server 这样可以快速启动和重启服务(自己试了下还是有问题,摸索中。。。。)
3. 登陆root账户更改默认密码
mysql -h 127.0.0.1 -u root -p 之后输入上一步的默认密码
执行show databases 会提示:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
更改默认密码:ALTER USER USER() IDENTIFIED BY '123456abc';
之后使用新密码登陆,再次执行show databases;
成功!之后可以创建用户,建表和使用了!
默认情况下root用户无法远程登录,解决方案:本地登陆后执行如下语句:
use mysql;
update user set host = '%' where user = 'root’;
FLUSH PRIVILEGES