MySQL5.7安装,小记录一下吧,每次安装都挺麻烦的

Linux安装MySQL

  1. 选择版本
    在这里插入图片描述
    在这里插入图片描述

  2. 下载MySQL5.7安装包

  3. 解压

tar -zxvf mysql-5.7.33-el7-x86_64.tar.gz
  1. 重命名
mv mysql-5.7.33-el7-x86_64 mysql-5.7.33
  1. 创建用户
# 创建用户组
groupadd mysql
# 创建用户
useradd -r -g mysql mysql
  1. 创建MySQL数据文件夹并授权
mkdir /data/mysql
chown -R mysql:mysql /data/mysql/
  1. 创建MySQL配置文件
vim /etc/my.cnf
  1. 添加配置

  1. 初始化安装
cd mysql-5.7.33/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/tools/mysql-5.7.33/ --datadir=/data/mysql/ --user=mysql --initialize
  1. 从日志中获取默认密码
    在这里插入图片描述
cat /data/mysql/mysql.err
2021-03-19T02:56:14.029616Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-03-19T02:56:14.071260Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-03-19T02:56:14.138845Z 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: aaf4895b-885e-11eb-9230-5254004d77d3.
2021-03-19T02:56:14.140141Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-03-19T02:56:14.981359Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-19T02:56:15.407297Z 1 [Note] A temporary password is generated for root@localhost: 3u;fy%)S<#0<
  1. 生成MySQL启动脚本
cp /usr/local/tools/mysql-5.7.33/support-files/mysql.server /etc/init.d/mysql
  1. 启动MySQL
[root@redismaster bin]# service mysql start
Starting MySQL. SUCCESS!
  1. 查看服务是否启动
[root@redismaster bin]# ps -ef | grep mysql
root     11007     1  0 02:59 pts/0    00:00:00 /bin/sh /usr/local/tools/mysql-5.7.33/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql    11240 11007  0 02:59 pts/0    00:00:00 /usr/local/tools/mysql-5.7.33/bin/mysqld --basedir=/usr/local/tools/mysql-5.7.33 --datadir=/data/mysql --plugin-dir=/usr/local/tools/mysql-5.7.33/lib/plugin --user=mysql --log-error=/data/mysql/mysql.err --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
root     12593  2619  0 03:03 pts/0    00:00:00 grep --color=auto mysql
  1. 登录MySQL服务,密码是上面日志中获取到的密码
[root@redismaster bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
  1. 修改默认密码
mysql> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
  1. 修改MySQL用户登录访问控制
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
  1. 尝试使用Navicat登录
    在这里插入图片描述

  2. 添加软连接,避免每次都需要到MySQL了目录中执行命令

ln -s  /usr/local/mysql/bin/mysql    /usr/bin

感谢大佬的分享,我自己实践了一把,并记录一下下,感谢。

https://blog.csdn.net/qq_37598011/article/details/93489404

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值