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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 [email protected]: 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. 创建[email protected]%

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. 查看数据库进程

[[email protected] 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

[[email protected] 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

[[email protected] etc]# sudo -u mysql service mysql.server start

Starting MySQL.. SUCCESS!


21. 查看服务

ps  -ef|grep mysql

[[email protected] 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

[[email protected] etc]# sudo -u mysql service mysql.server restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

技术分享图片技术分享图片

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

以上是关于CentOS 7.2 下 mysql 8.0.11二进制安装(亲测)的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7 下源码安装MySQL 8.0.11

Linux 下安装mysql 8.0.11(CentOS 7.4 系统)

CentOS 7 安装MySQL 8.0.11

CentOS 7.2下服务器配置(linux+apache+php+mysql)

CentOS 7.2 MySQL的root密码忘记时重置方法

centos7.2 本地yum安装mysql8.0.11-1