CentOS linux 安装 mysql8

在网上找了一大堆似乎没有一个可以完全安装好mysql8进行登录的,经过一番努力结果如下:

 

查看系统版本:

cat /etc/centos-releaseo
CentOS Linux release 8.0.1905 (Core) 

根据系统版本到mysql官网下载资源包

版本:Linux - Generic 

Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive

 

安装上传工具包

yum install -y lrzsz

 上传文件:

rz

 解压文件:

xz -d mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar

 

  移动文件:

mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql

创建data目录:

mkdir data

创建 mysql 用户组和 mysql 用户

groupadd mysql
useradd -g mysql mysql

改变 mysql 目录权限

chown -R mysql.mysql /usr/local/mysql/
或者
chown -R mysql .
chgrp -R mysql .

因为不会自动生成my.cnf说以手动创建:

touch /etc/my.cnf

修改内容:

vim my.cnf

 

[client]
socket = /usr/local/mysql/mysql.sock
default-character-set=utf8

[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock
character-set-server=UTF8MB4
port = 3306
bind-address = 0.0.0.0
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower-case-table-names=1 -- 注意初始化时需要初始化否则将该代码删掉

[mysql]
port= 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock 

 

ESC  保存

:wq 退出

 

 

更改目录权限

chown -R mysql:mysql /usr/local/mysql 

初始化数据库:

方式一:

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data //初始化数据库

方式二:

/usr/local/mysql/bin/mysqld --initialize --user=mysql

 方式三:

/usr/local/mysql/bin/mysqld --user=mysql --initialize --lower-case-table-names=1 --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

# 注意这里有个初始化大小写敏感问题 --lower-case-table-names=1
一定要对应:my.cnf 中 [mysqld] lower-case-table-names=1 否则报错
 

 

我用的方式三:


/usr/local/mysql/bin/mysqld --user=mysql --initialize --lower-case-table-names=1 --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

2020-06-13T03:46:50.420138Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 15677
2020-06-13T03:46:53.888639Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: evF.ixX!%8qo

A temporary password 后的临时密码要记住:evF.ixX!%8qo


配置MySql服务:

 
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld #好像报错,继续执行下面的
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig  --list mysqld

 

配置全局环境变量:
vi /etc/profile

在 profile 文件底部添加如下两行配置,保存后退出


export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH

保存退出后执行:

source /etc/profile

启动MySql服务:

service mysql start

/usr/local/mysql/support-files/mysql.server start

查看MySql启动状态:

service mysql status

 

密码登录:

mysql -uroot -p密码

修改密码:

update user set authentication_string='' where user='root';
FLUSH PRIVILEGES;

重新登陆:

alter user 'root'@'localhost' identified by '新密码';
FLUSH PRIVILEGES;

设置可以远程登录

mysql>use mysql
mysql>update user set host='%' where user='root' limit 1;

mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';
mysql>FLUSH PRIVILEGES;//最后要刷新权限

防火墙安装:

yum install firewalld
systemctl start firewalld
systemctl status firewalld

开通3306端口:

firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --add-port=3306/tcp

 查看开通状态:

netstat -an | grep 3306

 

这样我们就可以用Navicate For MySql进行登录了。




在/etc/my.cnf [mysqld] 下加 
skip-grant-tables  

免密码登录

 

重启:
service mysqld restart

 

posted @ 2020-04-16 11:51  wfpanskxin  阅读(313)  评论(0编辑  收藏  举报