Product Version:5.7.34 (选择需要的安装的版本)
Operating System:Linux - Generic
OS Version:Linux - Generic (glibc 2.12) (x86, 64-bit)
[root@db01 ~] wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@db01 ~]# useradd -d /mysql mysql
创建数据目录mysqldatadata
[root@db01 ~]# mkdir /mysqldata
[root@db01 ~] # cd /mysql
[root@db01 mysql]# tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@db01 mysql]# mv mysql-5.7.34-linux-glibc2.12-x86_64 mysql
[root@db01 ~]# vim /etc/profile
文档末尾添加一行:
export PATH=/mysql/mysql/bin:$PATH
[root@db01 ~]# source /etc/profile
[root@db01 mysql]# chown -R mysql.mysql /mysql/
[root@db01 mysql]# chown -R mysql.mysql /mysqldata
[root@db01 mysql]# su - mysql
2.5.1 方法一:空密码初始化
[mysql@db01 ~]$ mysqld --initialize-insecure --user=mysql --basedir=/mysql/mysql --datadir=/mysqldata/data3306
2023-02-10T11:43:55.986438Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-02-10T11:43:56.160842Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-02-10T11:43:56.187282Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-02-10T11:43:56.245398Z 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: 334f5788-a938-11ed-994e-000c29c29590.
2023-02-10T11:43:56.246209Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-02-10T11:43:56.776324Z 0 [Warning] CA certificate ca.pem is self signed.
2023-02-10T11:43:56.931947Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2.5.2 方法二:初始化管理员的临时密码
[mysql@db01 ~]$ mysqld --initialize --user=mysql --basedir=/mysql/mysql --datadir=/mysqldata/data3306
2023-02-10T11:48:07.185942Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-02-10T11:48:07.332038Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-02-10T11:48:07.354802Z 0 [Warning] InnoDB: Creating foreign key constraint sysyem tables.
2023-02-10T11:48:07.409689Z 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: c903f8a4-a938-11ed-a0ee-000c29c29590.
2023-02-10T11:48:07.410495Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-02-10T11:48:07.889229Z 0 [Warning] CA certificate ca.pem is self signed.
2023-02-10T11:48:07.964367Z 1 [Note] A temporary password is generated for root@localhost: jiS5riUYG0&5
管理员的临时密码为:root@localhost:jiS5riUYG0&5
新特性重要说明:
5.7开始,MySQL加入了全新的 密码的安全机制:
1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2.密码复杂度:长度:超过12位? 复杂度:字符混乱组合
3.密码过期时间180天
2.5.3 注释:5.6初始化的区别
/mysql/scripts/mysql_install_db --user=xxx --datadir=/xxx --basedir=/xxx
查看初始化配置文件的默认读取路径
[mysql@db01 ~]$ mysqld --help --verbose |grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
默认情况下,MySQL启动时,会依次读取以上配置文件,如果有重复选项,会以最后一个文件设置的为准。
但是,如果启动时加入了–defaults-file=xxxx时,以上的所有文件都不会读取.
创建存放配置文件目录:
[mysql@db01 ~]$ mkdir /mysql/conf
[mysql@db01 ~]$ cd /mysql/conf/
[mysql@db01 conf]$ vim my3306.cnf
[mysqld]
user=mysql
basedir=/mysql/msyql
datadir=/mysqldata/data3306
port=3306
server_id=1
socket=/mysqldata/data3306/mysql.sock
pid-file=/mysqldata/data3306/mysql.pid
log-error=/mysqldata/data3306/mysqld.err
log-bin=/mysqldata/data3306/mysql-bin
relay_log= /mysqldata/data3306/mysql-relay-bin
character-set-server=utf8
collation-server=utf8_general_ci
expire_logs_days=7
max_connections=500
[mysql]
socket=/mysqldata/data3306/mysql.sock
prompt=3306 [\\d]>
[mysql@db01 conf]$ mysqld_safe --defaults-file=/mysql/conf/my3306.cnf --user=mysql &
[1] 25219
[mysql@db01 conf]$ 2023-02-10T12:08:23.484465Z mysqld_safe Logging to '/mysqldata/data3306/mysqld.err'.
2023-02-10T12:08:23.510015Z mysqld_safe Starting mysqld daemon with databases from /mysqldata/data3306
[mysql@db01 ~]$ mysql -S /mysqldata/data3306/mysql.sock
报错:
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解决:切换到root用户安装软件包
[root@db01 ~]# yum install -y libaio-devel
[root@db01 ~]# yum install -y libncurses*
mysql> alter user root@'localhost' identified by '123123';
Query OK, 0 rows affected (0.00 sec)
方法一:
[root@db01 ~]# mysqladmin --socket=/iddbs/data3306/mysql.sock -uroot -p shutdown
方法二:
mysql> shutdown;