linux 安装mysql8
文章借鉴于 linux下安装mysql8
1 linux 下载 mysql8
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
2 解压
xz -d mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
解压到 /usr/local/mysql/ ,并修改名字位mysql
tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar -C /usr/local/mysql
3 创建用户组及用户和密码
groupadd mysql
useradd -g mysql mysql
4 授权用户
chown -R mysql.mysql /usr/local/mysql
5 编辑my.cnf文件
vim /etc/my.cnf
输入一下内容
[mysqld]
user=root
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
port=3306
max_connections=200
max_connect_errors=10
character-set-server=utf8
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
lower_case_table_names=1
group_concat_max_len=102400
[mysql]
default-character-set=utf8
[client]
port=3306
default-character-set=utf8
6 进入到bin目录下
初始化基础信息,最后一行后面会有个随机的初始密码保存下来一会登录要用(如果忘记了就删掉data重新初始化)
./mysqld --initialize
注意末尾的管理员临时登录密码
7 添加mysqld服务到系统
先返回到mysql目录
cd …
cp -a ./support-files/mysql.server /etc/init.d/mysql
8 授权以及添加服务
chmod +x /etc/init.d/mysql
chkconfig --add mysql
9 启动mysql
service mysql start
10 将mysql添加到命令服务
ln -s /usr/local/mysql/bin/mysql /usr/bin
11 登录mysql
mysql -uroot -pC3kGvKhLm,0=
12 更改root用户的密码
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY '123;
flush privileges;
13 更改mysql 的远程连接权限
use mysql;
update user set host=‘%’ where user = ‘root’;
flush privileges;
14 关闭防火墙
查看防火墙状态
sudo firewall-cmd --state
关闭防火墙命令:systemctl stop firewalld.service
开启防火墙:systemctl start firewalld.service
关闭开机自启动:systemctl disable firewalld.service
开启开机启动:systemctl enable firewalld.service