MySQL5.7.28安装及配置MySQL5.7.28安装及配置
⼀、环境准备
1.准备Centos7.9 虚拟机
IP: 192.168.10.102
hostname:db1
[mysql@db01 ~]$ hostname -I
192.168.10.102 192.168.122.1
[mysql@db01 ~]$ hostname
db01
2.清理历史环境
[root@db01 ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@db01 ~]# yum remove mariadb-libs.x86_64 -y
已加载插件:fastestmirror, langpacks
···
删除:
mariadb-libs.x86_64 1:5.5.68-1.el7
作为依赖被删除:
postfix.x86_64 2:2.10.1-9.el7
完毕!
3.创建⽤户和组
useradd mysql -s /sbin/nologin
4.创建相关路径
#创建软件⽬录
[root@db01 /]# mkdir -p /app/database/
#创建数据⽬录
[root@db01 /]# mkdir -p /data/3306/
#创建⽇志⽬录
[root@db01 /]# mkdir -p /binlog/3306/
5.设置权限
[root@db01 /]# chown -sql /app/ /data/ /binlog/
⼆、上传并解压 MySQL软件,并做软链接
[root@db01 app]# rz -E
rz waiting to receive.
[root@db01 app]# ls
database mysql-5.7.28-linux-glibc2.12-x86_
[root@db01 app]# mv mysql-5.7.28-linux-glibc2.12-x86_ ./database/ [root@db01 app]# cd database/
[root@db01 database]# ls
mysql-5.7.28-linux-glibc2.12-x86_
[root@db01 database]# tar xf mysql-5.7.28-linux-glibc2.12-x86_
[root@db01 database]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
[root@db01 database]# cd mysql
[root@db01 mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@db01 mysql]# ls -l
总⽤量 292
drwxr-xr-x. 2 root root 4096 5⽉ 28 14:55 bin
drwxr-xr-x. 2 root root 55 5⽉ 28 14:55 docs
drwxr-xr-x. 3 root root 4096 5⽉ 28 14:54 include
drwxr-xr-x. 5 root root 230 5⽉ 28 14:55 lib
-rw-r--r--. 1 7161 31415 279547 9⽉ 27 2019 LICENSE
drwxr-xr-x. 4 root root 30 5⽉ 28 14:55 man
-rw-r--r--. 1 7161 31415 587 9⽉ 27 2019 README
drwxr-xr-x. 28 root root 4096 5⽉ 28 14:55 share
drwxr-xr-x. 2 root root 90 5⽉ 28 14:55 support-files
[root@db01 mysql]# chown -R mysql. *
[root@db01 mysql]# ll
总⽤量 292
drwxr-xr-x. 2 mysql mysql 4096 5⽉ 28 14:55 bin
drwxr-xr-x. 2 mysql mysql 55 5⽉ 28 14:55 docs
drwxr-xr-x. 3 mysql mysql 4096 5⽉ 28 14:54 include
drwxr-xr-x. 5 mysql mysql 230 5⽉ 28 14:55 lib
-rw-r--r--. 1 mysql mysql 279547 9⽉ 27 2019 LICENSE
drwxr-xr-x. 4 mysql mysql 30 5⽉ 28 14:55 man
-rw-r--r--. 1 mysql mysql 587 9⽉ 27 2019 README
drwxr-xr-x. 28 mysql mysql 4096 5⽉ 28 14:55 share
drwxr-xr-x. 2 mysql mysql 90 5⽉ 28 14:55 support-files
注:
bin:存放命令,需将其设置为环境变量路径,调⽤命令时就⽆需写全路径了support-files:存放脚本
三、设置环境变量
1.设置环境变量
在/etc/profile⽂件中添加环境变量路径
[root@db01 mysql]# vim /etc/profile
export PATH=$PATH:/app/database/mysql/bin:$PATH
2.⽣效配置
[root@db01 mysql]# source /etc/profile
3.验证是否⽣效
[root@db01 mysql]# mysql -V
mysql Ver 14.14 Distrib 5.7.28, for linux-glibc2.12 (x86_64) using E
ditLine wrapper
四、初始化系统
[root@db01 mysql]# mysqld --initialize --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
2021-05-28T07:12:29.033058Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --exp
licit_defaults_for_timestamp server option (see documentation for more details).2021-05-28T07:12:30.047291Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-28T07:12:30.222548Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-28T07:12:30.315050Z 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: 10c953fa-bf84-11eb-bcd4-000c293f0f29.2021-05-28T07:12:30.320622Z 0 [Warning] Gtid t able is not ready to be used. Table 'id_executed' canno
t be opened.2021-05-28T07:12:32.029162Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-28T07:12:32.271647Z 1 [Note] A temporary password is generated for root@localhost: <*Ey*7BFsdai
[root@db01 mysql]#
扩展:
5.7初始化⽅式
(1)初始化完成后,会有12位临时密码,但是必须在使⽤MySQL之前重置这个密码。
(2)密码管理使⽤严格模式:3种密码复杂度,密码长度⽆限制。
关闭MySQL,清空数据⽬录下的⽂件,选择mysqld --initialize-insecure⽅式初始化
[root@db01 3306]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@db01 3306]# rm -rf ./*
[root@db01 3306]# mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
2021-05-28T08:02:57.668622Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation
for more details).2021-05-28T08:02:57.932748Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-28T08:02:57.992227Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-28T08:02:58.062053Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Ge nerating a new UUID:
1d76db33-bf8b-11eb-b078-000c293f0f29.2021-05-28T08:02:58.066369Z 0 [Warning] Gtid table is not ready to be used. Table 'id_executed' can not be opened.
2021-05-28T08:03:00.100654Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-28T08:03:00.601026Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure optio n.
[root@db01 3306]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/'.
SUCCESS!
[root@db01 3306]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 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>
5.6版本初始化⽅式
/app/database/mysql/scripts/mysql_install_db --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/
五、配置⽂件设置
[root@db01 mysql]# cat > /etc/myf <<EOF
> [mysqld]
> user=mysql
> basedir=/app/database/mysql
> datadir=/data/3306
mysql下载starting the server> server_id=6
> port=3306
> socket=/tmp/mysql.sock
> [mysql]
> socket=/tmp/mysql.sock
> EOF
六、准备 MySQL启动脚本
将启动脚本拷贝到系统软件管理⽬录下,⽅便调⽤
[root@db01 mysql]# cd /app/database/mysql/support-files/
[root@db01 support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld
注:
centos6 启动
[root@db01 support-files]# service mysqld start
Starting MySQL.Logging to '/data/'.
.. SUCCESS!
[root@db01 support-files]# service mysqld stop
Shutting down MySQL.. SUCCESS!
centos7 启动
将/etc/init.d/mysqld添加到system管理中
[root@db01 support-files]# chkconfig --add mysqld
[root@db01 support-files]# systemctl start mysqld
七、登陆前修改原始密码(mysqld --initialize⽅式初始化):
[root@db01 support-files]# mysqladmin -uroot -p password qwe@123
[root@db01 support-files]# Enter password:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论