发新帖

[MySQL] mysql-8.0.20 Linux 安装

零下一度 2020-6-24 914

1、下载mysql-8.0.20

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar

2、解压安装包

tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

将解压的文件夹重命名mysql,拷贝到usr/local

cp mysql /usr/local
cd /usr/local/mysql
mkdir data

3、编辑my.cnf

[client]
port=3306
socket=/tmp/mysql/mysql.sock
default-character-set=utf8

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=/fdisk1/logs/mysql.log
default_authentication_plugin=mysql_native_password

# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
transaction_isolation = READ-COMMITTED
# 服务端使用的字符集默认为UTF8
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
lower_case_table_names = 1

#skip-grant-tables

4、创建用户

groupadd mysql
useradd -g mysql mysql

5、更改目录权限

chown -R mysql:mysql /tmp/mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /tmp/mysql

6、初始化

./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

7、初始化密码

初始化时并没有出现 初始密码,因此需要修改密码。

将my.cnf 中的skip-grant-tables去掉注释,可以使用无密码登录

启动MySQL

./support-files/mysql.server start

a,清空密码

use mysql

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

b,注释skip-grant-tables,在登录MySQL

mysql -u root -p

c,修改密码

alter user 'root'@'localhost' identified by 'admin'

8、设置自动启动

ln ./support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
cd /etc/init.d
chkconfig --add mysql
chkconfig --level 345 mysql on
server mysql restart

9、远程连接

a,在my.cnf中mysqld下添加

default_authentication_plugin=mysql_native_password

b,进入mysql命令行

use mysql
update user set Host='%' where user='root';
alert user 'root'@'localhost' identified with mysql_native_password by 'admin';
flush privileges;


最新回复 (0)
返回
零下一度
主题数
930
帖子数
0
注册排名
1