Mysql 5.7.26 安装
Mysql 5.7.26 安装
1、解压并移动
tar -xvf mysql-advanced-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-advanced-5.7.26-linux-glibc2.12-x86_64/ /usr/local/mysql-5.7.26
2、创建 用户,并给数据目录赋予权限
groupadd mysql
useradd -r -g mysql mysql
3、创建mysq数据目录
mkdir -p /data
cd /data/
mkdir -p mysql
chown mysql:mysql -R /data/mysql
4、配置参数
vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql-5.7.26
datadir=/data/mysql
socket=/tmp/mysql.sock
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqld_safe]
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
5、初始化mysql
# cd /usr/local/mysql-5.7.26/bin/
# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql-5.7.26/ --datadir=/data/mysql/ --user=mysql --initialize
2025-11-10T02:31:40.748640Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
100
100
100
2025-11-10T02:32:02.984938Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-11-10T02:32:03.314752Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-11-10T02:32:03.402117Z 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: 71416dec-bddd-11f0-8e4b-000c29fadf64.
2025-11-10T02:32:03.404596Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-11-10T02:32:05.425531Z 0 [Warning] CA certificate ca.pem is self signed.
2025-11-10T02:32:06.048298Z 1 [Note] A temporary password is generated for root@localhost: oYU%R%T>e6UY
[root@yashan bin]#
6、修改启动配置
cd /usr/local/mysql-5.7.26/support-files
# cp mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld
basedir=/usr/local/mysql-5.7.26
datadir=/data/mysql
配置开启自启
如果rc.local文件没有执行权限,所以需要手动开启:
echo "service mysql start" >> /etc/rc.local
7、启动mysql,并更改root 密码
# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/mysql.err'.
.......... SUCCESS!
# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26-enterprise-commercial-advanced
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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> alter user root@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
注:需要设置root用户可以远程访问,需执行如下命令:
mysql> grant all privileges on *.* to root@'192.168.142.1' identified by 'root' with grant option;
mysql> flush privileges;
