本文主要介绍MysqL 8.0.11二进制安装,具体步骤如下
1. 解压文件
tar -zxvf MysqL-8.0.11-el7-x86_64.tar.gz
@H_404_7@
mv MysqL-8.0.11-el7-x86_64 /usr/local/MysqL
@H_404_7@
3. 创建MysqL组
groupadd MysqL
@H_404_7@
@H_404_7@
5. 创建data目录
mkdir /data
@H_404_7@
6. 修改目录权限
chown -R MysqL.MysqL /usr/local/MysqL
@H_404_7@
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
@H_404_7@
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
@H_404_7@
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
@H_404_7@
10. 启动数据库
/usr/local/MysqL/bin/MysqLd_safe --defaults-file=/etc/my.cnf --user=MysqL &
@H_404_7@
[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
@H_404_7@
/usr/local/MysqL/bin/MysqL -uroot -p
@H_404_7@
alter user 'root'@'localhost' identified with MysqL_native_password by '123456'
@H_404_7@
13. 创建root@%
create user 'root'@'%' identified by '123456';
grant all privileges on *.* to 'root'@'%' with grant option;@H_404_7@
flush privileges;@H_404_7@
@H_404_7@
14. 配置环境变量
vi /etc/profile 在最后添加:
PATH=/usr/local/MysqL/bin:/usr/local/MysqL/lib:$PATH
source /etc/profile
@H_404_7@
MysqLadmin -uroot -p shutdown
@H_404_7@
16. 启动数据库
MysqLd_safe --defaults-file=/etc/my.cnf --user=MysqL &
@H_404_7@
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
@H_404_7@
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
@H_404_7@
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)
@H_404_7@
20. 启动数据库
sudo -u MysqL service MysqL.server start
[root@MysqL02 etc]# sudo -u MysqL service MysqL.server start
Starting MysqL.. SUCCESS!
@H_404_7@
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
@H_404_7@
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)
原文链接:https://www.f2er.com/centos/374119.html