环境
OS:Centos 7
1.下载安装介质
官网下载
我这里下载的是8.0.17
MysqL-8.0.17-linux-glibc2.12-x86_64.tar.xz
#groupadd MysqL
#useradd -g MysqL MysqL
#passwd MysqL
3.下载解压安装
[[email protected] soft]# tar -xvf MysqL-8.0.17-linux-glibc2.12-x86_64.tar.xz
[[email protected] soft]# mv MysqL-8.0.17-linux-glibc2.12-x86_64 /opt/mha/MysqL8
4.创建相应的目录
[[email protected] MysqL8]# mkdir redolog ##redo日志文件
[[email protected] MysqL8]# mkdir -p MysqLlog/relaylog ##主从环境relaylog
[[email protected] MysqL8]# mkdir -p MysqLlog/binlog ##binlog文件
[[email protected] MysqL8]# mkdir ibdata ##ibdata文件
5.初始化数据库
root账户下
[[email protected] bin]# ./MysqLd --initialize --user=MysqL --basedir=/opt/mha/MysqL8 --datadir=/opt/mha/MysqL8/data
2019-09-05T08:25:17.210466Z 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.
2019-09-05T08:25:17.210613Z 0 [System] [MY-013169] [Server] /opt/mha/MysqL8/bin/MysqLd (MysqLd 8.0.17) initializing of server in progress as process 25951
2019-09-05T08:25:38.288278Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: vew-DWj=q4r<
2019-09-05T08:25:49.555673Z 0 [System] [MY-013170] [Server] /opt/mha/MysqL8/bin/MysqLd (MysqLd 8.0.17) initializing of server has complete
这里初始化密码为vew-DWj=q4r<
若不想要初始化密码,不需要密码的话可以采用如下方法初始化话
./MysqLd --initialize-insecure --user=MysqL --basedir=/opt/mha/MysqL8 --datadir=/opt/mha/MysqL8/data
vi /opt/mha/MysqL8/conf/my.cnf
server-id=134
port=13306
basedir=/opt/mha/MysqL8
datadir=/opt/mha/MysqL8/data
socket=/opt/mha/MysqL8/MysqL.sock
character-set-server=utf8mb4
max_connections = 1500
binlog_format=row
log-bin=/opt/mha/MysqL8/MysqLlog/binlog/binlog
slow_query_log_file=/opt/mha/MysqL8/MysqLlog/logfile/slow-query.log
log-error=/opt/mha/MysqL8/MysqLlog/logfile/MysqL-err.log
relay-log-index=/opt/mha/MysqL8/MysqLlog/relaylog/slave-relay-bin.index
relay-log=/opt/mha/MysqL8/MysqLlog/relaylog/relaylog-binlog
gtid_mode=ON
enforce_gtid_consistency = ON
event_scheduler=1
8.启动
[[email protected] bin]$ /opt/mha/MysqL8/bin/MysqLd_safe --defaults-file=/opt/mha/MysqL8/conf/my.cnf --user=MysqL &
9.登陆数据库修改相应用户密码
[[email protected] bin]$ ./MysqL -h 127.0.0.1 -uroot -P13306 -S /opt/mha/MysqL8/MysqL.sock -p
MysqL> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
alter user ‘root‘@‘localhost‘ identified by ‘MysqL‘;
flush privileges;
10.重新登录
[[email protected] bin]$ ./MysqL -h localhost -uroot -P13306 -S /opt/mha/MysqL8/MysqL.sock -pMysqL
MysqL> select version();
+-----------+
| version() |
+-----------+
| 8.0.17 |
+-----------+
1 row in set (0.00 sec)
11.创建开发用户
在MysqL8.0创建用户和授权和之前不太一样了,其实严格上来讲,也不能说是不一样,只能说是更严格,MysqL8.0需要先创建用户(创建用户时要带@并指定地址,则grant授权时的地址就是这个@后面指定的!,否则grant授权就会报错!)和设置密码,然后才能授权。
create user ‘hxl‘@‘%‘ identified by ‘MysqL‘;
grant all privileges on *.* to ‘hxl‘@‘%‘ with grant option;
采用5.7之前的办法创建用户会报错
MysqL> grant all privileges on *.* to ‘hxl01‘@‘%‘ identified by ‘MysqL‘;
ERROR 1064 (42000): You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near ‘identified by ‘MysqL‘‘ at line 1