MySQL数据库安装--初始化方式
Look:324,By admin Posted On 2021-08-31
摘自:https://www.jianshu.com/p/e872bc12f583
1、5.7初始化方法:
1.1初始化数据,初始化管理员的临时密码
$ mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql 2019-04-18T03:21:53.381108Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-04-18T03:21:54.583415Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-04-18T03:21:54.697859Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-04-18T03:21:54.760821Z 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: 1daa0c57-6189-11e9-bc80-000c294234c8. 2019-04-18T03:21:54.770856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-04-18T03:21:54.772016Z 1 [Note] A temporary password is generated for root@localhost: 9LN.fh_Ea#uU
新特性重要说明:
5.7开始,MySQL加入了全新的 密码的安全机制:
1.初始化完成后,会生成临时密码(显示到屏幕上,并且会往日志中记一份)
2.密码复杂度:长度:超过12位? 复杂度:字符混乱组合
3.密码过期时间180天
1.2初始化数据,初始化管理员的密码为空
[root@localhost ~]# \rm -rf /data/mysql/* [root@localhost ~]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql 2019-04-18T03:37:43.146018Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-04-18T03:37:43.892132Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-04-18T03:37:43.970412Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-04-18T03:37:44.029490Z 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: 5378f3b3-618b-11e9-9164-000c294234c8. 2019-04-18T03:37:44.041469Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-04-18T03:37:44.042348Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2、5.6初始化的区别
$ /application/mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
3、默认配置文件
[mysqld] user=mysql basedir=/usr/local/mysql datadir=/data/mysql server_id=6 port=3306 socket=/tmp/mysql.sock [mysql] socket=/tmp/mysql.sock
4.使用systemd管理mysql
vim /etc/systemd/system/mysqld.service [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf LimitNOFILE = 5000
5.修改用户密码方法
mysql>set password for root@localhost = password('xxxxx'); mysql>alter user root@localhost identified by 'xxxxx'; #column password/authentication_string mysql>update mysql.user set authentication_string=password('xxxxxx') where user='xxxx' and Host ='localhost'; mysql>flush privileges; mysql>grant all privileges on *.* to root@localhost identified by 'xxxxxx'; mysqladmin -uroot -p oldpass password newpass