MySQL安装
# 1 下载解压安装包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
# 解压
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql
# 重命名
cd /usr/local/mysql
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql-5.7.26
1
2
3
4
5
6
2
3
4
5
6
# 2 修改配置
创建mysql用户组和用户并修改权限
groupadd mysql
useradd -r -g mysql mysql
1
2
2
创建数据目录并赋予权限
mkdir -p /data/mysql
chown mysql:mysql -R /data/mysql
1
2
2
创建一个my_default.cnf文件,并且将信息写入到 my_default.cnf 中
touch my_default.cnf
vim my_default.cnf
1
2
2
[client]
host=0.0.0.0
user='user'
password='password'
[mysqld]
socket=/tmp/mysql.sock
symbolic-links=0
server-id=2
port=3306
#最大连接数
max_connections=2000
#表大小写忽略
lower_case_table_names = 1
#安装目录
basedir=/usr/local/mysql/mysql-5.7.26
#数据存放目录
datadir=/data/mysql
log_bin=mysql-bin
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_allowed_packet = 1024M
[mysqld_safe]
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
!includedir/etc/my.cnf.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
拷贝文件my_default.cnf到my.cnf中,执行命令后会询问你是否要覆盖,输入y即可
cp my_default.cnf /etc/my.cnf
1
进入mysql的bin目录、执行初始化、查看随机的临时密码
cd /usr/local/mysql/mysql-5.7.26/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/mysql-5.7.26/ --datadir=/data/mysql/ --user=mysql --initialize
1
2
3
2
3
输出结果
2022-05-19T09:34:46.051122Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-05-19T09:34:46.051178Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2022-05-19T09:34:46.292249Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-05-19T09:34:46.338305Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-05-19T09:34:46.417671Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ebc239f0-d756-11ec-bf55-525400c84c69.
2022-05-19T09:34:46.420836Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-05-19T09:34:46.423347Z 1 [Note] A temporary password is generated for root@localhost: HJ2zXu>ltE:9
1
2
3
4
5
6
7
2
3
4
5
6
7
# 3 启动服务
将mysql.server放置到/etc/init.d/mysql中、启动mysql服务、查看mysql服务启动信息
cp /usr/local/mysql/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysql
service mysql start
1
2
3
2
3
进入mysql安装的bin目录中,连接mysql。密码为前面生成的:HJ2zXu>ltE:9
cd /usr/local/mysql/mysql-5.7.26/bin
./mysql -u root -p
1
2
3
2
3
设置新密码、设置用户权限、刷新配置
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
1
2
3
4
5
2
3
4
5
设置远程连接的配置信息
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
1
2
3
4
2
3
4
上次更新: 2022/06/02, 11:20:10