CentOS 7.2 下 mysql 8.0.11二进制安装(亲测)

前端之家收集整理的这篇文章主要介绍了CentOS 7.2 下 mysql 8.0.11二进制安装(亲测)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文主要介绍MysqL 8.0.11二进制安装,具体步骤如下

1. 解压文件

tar -zxvf MysqL-8.0.11-el7-x86_64.tar.gz


2. 移动解压后的数据库文件

mv MysqL-8.0.11-el7-x86_64 /usr/local/MysqL


3. 创建MysqL

groupadd MysqL


4. 创建MysqL用户添加MysqL

useradd -g MysqL MysqL


5. 创建data目录

mkdir /data


6. 修改目录权限

chown -R MysqL.MysqL /data

chown -R MysqL.MysqL /usr/local/MysqL


7. 创建my.cnf文件(etc目录下已有my.cnf,可先删除)

vi /etc/my.cnf

[MysqLd]

port = 3306

socket = /tmp/MysqL.sock

basedir = /usr/local/MysqL

datadir = /data

log-error = MysqL02_err.log

server-id = 330602


8.初始化数据库

(MysqL 8.0.11是没有/bin/MysqL_install_db脚本的,有的人写教程仍在用来误导新人,安装不成功的请注意。官档可查)

#有密码初始化

/usr/local/MysqL/bin/MysqLd --defaults-file=/etc/my.cnf --user=MysqL --initialize

无密码初始化

/usr/local/MysqL/bin/MysqLd --defaults-file=/etc/my.cnf --user=MysqL --initialize-insecure


9. 查看密码

cat /data/MysqL02_err.log

2018-07-25T14:10:46.576739Z 0 [System] [MY-013169] [Server] /usr/local/MysqL/bin/MysqLd (MysqLd 8.0.11) initializing of server in progress as process 9796

2018-07-25T14:10:49.072963Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: iN:.snX3P_in

2018-07-25T14:10:50.825865Z 0 [System] [MY-013170] [Server] /usr/local/MysqL/bin/MysqLd (MysqLd 8.0.11) initializing of server has completed


10. 启动数据库

/usr/local/MysqL/bin/MysqLd_safe --defaults-file=/etc/my.cnf --user=MysqL &


[1] 9925

2018-07-25T14:20:27.230347Z MysqLd_safe Logging to '/data/MysqL02_err.log'.

2018-07-25T14:20:27.267638Z MysqLd_safe Starting MysqLd daemon with databases from /data


11. 登录数据库

/usr/local/MysqL/bin/MysqL -uroot -p


12. 第一次登录修改root初始化密码

alter user 'root'@'localhost' identified with MysqL_native_password by '123456'


13. 创建root@%

create user 'root'@'%' identified by '123456';

grant all privileges on *.* to 'root'@'%' with grant option;

flush privileges;


14. 配置环境变量

vi /etc/profile 在最后添加

PATH=/usr/local/MysqL/bin:/usr/local/MysqL/lib:$PATH

source /etc/profile


15. 关闭数据库

MysqLadmin -uroot -p shutdown


16. 启动数据库

MysqLd_safe --defaults-file=/etc/my.cnf --user=MysqL &


17. 查看数据库进程

[root@MysqL02 data]# ps -ef|grep MysqL

root 10253 9892 0 10:48 pts/2 00:00:00 /bin/sh /usr/local/MysqL/bin/MysqLd_safe --defaults-file=/etc/my.cnf --user=MysqL

MysqL 10405 10253 16 10:48 pts/2 00:00:01 /usr/local/MysqL/bin/MysqLd --defaults-file=/etc/my.cnf --basedir=/usr/local/MysqL --datadir=/data --plugin-dir=/usr/local/MysqL/lib/plugin --user=MysqL --log-error=MysqL02_err.log --pid-file=MysqL02.pid --socket=/tmp/MysqL.sock --port=3306

root 10447 9892 0 10:49 pts/2 00:00:00 grep --color=auto MysqL


18. 将MysqL服务加到系统服务中

cp -a /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqL.server

chmod +x /etc/rc.d/init.d/MysqL.server

chkconfig --add MysqL.server

chkconfig --list MysqL.server


19. 关闭数据库

service MysqL.server stop

[root@MysqL02 etc]# service MysqL.server stop

Shutting down MysqL..2018-07-25T15:33:26.490180Z MysqLd_safe MysqLd from pid file /data/MysqL02.pid ended

SUCCESS!

[1]+ Done MysqLd_safe --defaults-file=/etc/my.cnf --user=MysqL (wd: /data)

(wd now: /etc)


20. 启动数据库

sudo -u MysqL service MysqL.server start

[root@MysqL02 etc]# sudo -u MysqL service MysqL.server start

Starting MysqL.. SUCCESS!


21. 查看服务

ps -ef|grep MysqL

[root@MysqL02 etc]# ps -ef|grep MysqL

MysqL 10833 1 0 11:35 pts/2 00:00:00 /bin/sh /usr/local/MysqL/bin/MysqLd_safe --datadir=/data --pid-file=/data/MysqL02.pid

MysqL 11003 10833 10 11:35 pts/2 00:00:00 /usr/local/MysqL/bin/MysqLd --basedir=/usr/local/MysqL --datadir=/data --plugin-dir=/usr/local/MysqL/lib/plugin --log-error=MysqL02_err.log --pid-file=/data/MysqL02.pid --socket=/tmp/MysqL.sock --port=3306

root 11047 9892 0 11:36 pts/2 00:00:00 grep --color=auto MysqL


22. 重启数据库

sudo -u MysqL service MysqL.server restart

[root@MysqL02 etc]# sudo -u MysqL service MysqL.server restart

Shutting down MysqL.. SUCCESS!

Starting MysqL. SUCCESS!

(本文出处:易语随风去 http://blog.51cto.com/aimax)

猜你在找的CentOS相关文章