centos7安装mysql8,并开机自动启动

1.下载

[root ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.30-el7-x86_64.tar

2.解包解压缩

cd /usr/local/
mv ~/mysql-8.0.30-el7-x86_64.tar .
tar -xvf mysql-8.0.30-el7-x86_64.tar
tar -zxvf mysql-8.0.30-el7-x86_64.tar.gz
mv mysql-8.0.30-el7-x86_64/ mysql

3.权限设置

groupadd mysql
useradd -r -g mysql mysql
chmod -R 755 /usr/local/mysql/

4.初始化

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

初始化后会出现一个初始化的临时密码,后续可以改掉改成自己需要的

2024-05-19T07:40:31.842222Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2024-05-19T07:40:31.842315Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process 12368
2024-05-19T07:40:31.850300Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-05-19T07:40:32.823917Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-05-19T07:40:34.192142Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root: gw4O?1JPnirl  #这里是生成的临时密码

最后一行是生成的临时密码 gw4O?1JPnirl第8步初次登录时输入这个

5.配置参数文件

vi /etc/my.cnf // 配置文件的位置,是/usr/local/mysql/support-files/mysql.server文件里默认的
chmod 755 /etc/my.cnf

文件内容是

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

[mysql]  
default-character-set = utf8mb4

[mysqld]  
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'

port = 3306
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
datadir = /usr/local/mysql/data
#lower_case_table_names=1
#如果要设置lower_case_table_names可以在初始化里面设置 ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

6.启动mysql

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

7.设置软连接,并重启MySQL

ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/mysql.sock /var/mysql.sock
service mysql restart

8.登录并更改密码

[root bin]# mysql -uroot -p
Enter password: # 输入初始化时产生的随机密码

9.改变密码

alter user 'root'@'localhost' identified by '123456';
set password for root = '123456';

10.开放远程连接

mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;    //刷新权限

11.创建systemctl 命令启动的service文件

只有创建了此service文件,才可以调用systemctl启动和关闭mysql服务

vi  /usr/lib/systemd/system/mysql.service

设置mysql.service内容

[Unit]
Description=The mysql service
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

12.MySQL启动和停止

service mysql start
systemctl start mysql
service mysql stop
systemctl stop mysql
service mysql restart
systemctl restart mysql

13.mysql开机启动

systemctl enable mysql.service
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值