3. 创建数据存储路径,并进行授权。企业中建议使用独立的一块硬盘用来存储数据或者挂存储服务器。
[root@templates tools]# mkdir -p /data/mysql/ data #<==== 创建数据存储路径 [root@templates tools]# chown -R mysql.mysql / data #<==== 授权 [root@templates tools]# chown -R mysql.mysql /application/ #<==== 授权
4. 初始化数据库
方式一:利用 initialize 参数初始化同时,给数据库root@localhost用户设置一个临时密码,该密码过期时间为180天,12位字符(包括大小写字母、数字和字符组成)。
[root@templates ~]# mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/data/mysql/ data 2021 - 03 -02T09: 51 : 00 .108059Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021 - 03 -02T09: 51 : 00 .479634Z 0 [Warning] InnoDB: New log files created, LSN= 45790 2021 - 03 -02T09: 51 : 00 .560426Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021 - 03 -02T09: 51 : 00 .631505Z 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: cb7034eb-7b3c-11eb-b8e8- 005056b484f7. 2021 - 03 -02T09: 51 : 00 .634190Z 0 [Warning] Gtid table is not ready to be used. Table ‘ mysql.gtid_executed ‘ cannot be opened. 2021 - 03 -02T09: 51 : 00 .635779Z 1 [Note] A temporary password is generated for root@localhost: Juy:kr/fp9LB
方式二:利用 initialize-insecure 参数,无临时密码。
[root@templates ~]# mysqld --initialize-insecure --basedir=/application/mysql --datadir=/data/mysql/ data 2021 - 03 -02T09: 57 : 59 .911031Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021 - 03 -02T09: 58 : 00 .396741Z 0 [Warning] InnoDB: New log files created, LSN= 45790 2021 - 03 -02T09: 58 : 00 .574981Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021 - 03 -02T09: 58 : 00 .688947Z 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: c5cfe2b3-7b3d-11eb-81fb- 005056b484f7. 2021 - 03 -02T09: 58 : 00 .691947Z 0 [Warning] Gtid table is not ready to be used. Table ‘ mysql.gtid_executed ‘ cannot be opened. 2021 - 03 -02T09: 58 : 00 .693066Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
【注意】如遇到以下报错,解放方法如下
报错: mysqld:error while loading shared libraries:libaio.so. 1 :cannot open shared object file : No such file or directory
处理方法:
yum install libaio-devel -y
5. 编辑数据库配置文件
[root@templates ~]# vim /etc/ my.cnf [mysqld] user = mysql basedir =/application/ mysql datadir =/data/mysql/ data socket =/tmp/ mysql.sock server_id = 6 port = 3306 [mysql] socket =/tmp/mysql.sock
6. 启动数据库
方式一:sys -v 方式启动
[root@templates ~]# cp /application/mysql/support-files/mysql.server /etc/init.d/ mysqld [root@templates data]# service mysqld start Starting MySQL. SUCCESS ! [root@templates data]# netstat - lntup Active Internet connections (only servers) Proto Recv -Q Send-Q Local Address Foreign Address State PID/ Program name tcp 0 0 0.0 . 0.0 : 22 0.0 . 0.0 :* LISTEN 1356 / sshd tcp6 0 0 ::: 3306 :::* LISTEN 1083 / mysqld tcp6 0 0 ::: 22 :::* LISTEN 1356 / sshd [root@templates data]# netstat -lntup| grep 3306 tcp6 0 0 ::: 3306 :::* LISTEN 1083 /mysqld
[root@templates data]# service mysqld stop
方式二:systemd方式启动
[root@templates data]# 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 =/application/mysql/bin/mysqld --defaults- file =/etc/ my.cnf LimitNOFILE = 5000
[root@templates data]# systemctl start mysqld [root@templates data]# netstat -lntup| grep 3306 tcp6 0 0 ::: 3306 :::* LISTEN 1224 / mysqld [root@templates data]# systemctl stop mysqld [root@templates data]# netstat -lntup| grep 3306
【注意】如果用sys-v方式启动数据库,就必须使用该方式进行停止。反之则一样。不能用两种方式中的一种进行启动,而另一种进行关闭数据库!
7. 管理员密码设定
[root@templates data]# mysqladmin -uroot - p password xxx #<==== 设置数据库管理员密码 Enter password: #<==== 输入旧密码,如果初始化时无临时密码,直接回车即可。后续更改密码也可以使用该命令,但是要输入旧密码。 mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
8. 数据库登录验证
[root@templates data]# 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 MySQL Community Server (GPL) 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 > select user,host from mysql.user; +---------------+-----------+ | user | host | +---------------+-----------+ | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 3 rows in set ( 0.00 sec)
部署完成!
Linux系统中MySQL 5.7.26的安装及初始化操作
标签:echo lin 必须 系统 res 回车 dem match 数据库管理员
查看更多关于Linux系统中MySQL 5.7.26的安装及初始化操作的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did117671