Linux-安装-MySQL5.7

2022/5/10 19:00:43

本文主要是介绍Linux-安装-MySQL5.7,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、二进制安装MySQL5.7

安装相关包

yum  -y install libaio numactl-libs

用户和组

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
[root@centos7-liyj ~]#groupadd mysql
[root@centos7-liyj ~]#useradd -r -g mysql -s /bin/false mysql   #创建系统用户
[root@centos7-liyj ~]#tail /etc/passwd
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
liyanjin:x:1000:1000:liyanjin:/home/liyanjin:/bin/bash
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
mysql:x:998:1001::/home/mysql:/bin/false
用户和组建立

下载二进制程序文件

下载路径http://mirrors.163.com/mysql/Downloads/MySQL-5.7/
Linux系统中:http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

 

准备程序文件

[root@centos7-liyj ~]#tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@centos7-liyj ~]#cd /usr/local/
[root@centos7-liyj /usr/local]#ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@centos7-liyj /usr/local]#chown -R root.root /usr/local/mysql/
[root@centos7-liyj /usr/local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos7-liyj /usr/local]#. /etc/profile.d/mysql.sh 

 

修改前文件内容属组属主
[root@centos7-liyj /usr/local/mysql]#ll
total 272
drwxr-xr-x  2 root root    4096 May 10 09:37 bin
drwxr-xr-x  2 root root      55 May 10 09:37 docs
drwxr-xr-x  3 root root    4096 May 10 09:37 include
drwxr-xr-x  5 root root     230 May 10 09:37 lib
-rw-r--r--  1 7161 31415 259253 Nov 30 04:09 LICENSE
drwxr-xr-x  4 root root      30 May 10 09:37 man
-rw-r--r--  1 7161 31415    566 Nov 30 04:09 README
drwxr-xr-x 28 root root    4096 May 10 09:37 share
drwxr-xr-x  2 root root      90 May 10 09:37 support-files
修改后文件内容属组属主
[root@centos7-liyj /usr/local/mysql]#ll
total 272
drwxr-xr-x  2 root root   4096 May 10 09:37 bin
drwxr-xr-x  2 root root     55 May 10 09:37 docs
drwxr-xr-x  3 root root   4096 May 10 09:37 include
drwxr-xr-x  5 root root    230 May 10 09:37 lib
-rw-r--r--  1 root root 259253 Nov 30 04:09 LICENSE
drwxr-xr-x  4 root root     30 May 10 09:37 man
-rw-r--r--  1 root root    566 Nov 30 04:09 README
drwxr-xr-x 28 root root   4096 May 10 09:37 share
drwxr-xr-x  2 root root     90 May 10 09:37 support-files
权限修改前后对比

准备环境变量

[root@centos7-liyj /usr/local]#echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@centos7-liyj /usr/local]#. /etc/profile.d/mysql.sh 

准备配置文件

[root@centos7-liyj /usr/local]#cp /etc/my.cnf{,.bak}
[root@centos7-liyj /usr/local]#vim /etc/my.cnf

[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

[client]
socket=/data/mysql/mysql.sock

初始化数据库文件并提取root密码

[root@centos7-liyj /data]#mysqld --initialize --user=mysql --datadir=/data/mysql
[root@centos7-liyj /data/mysql]#awk '/temporary password/{print $NF}' /data/mysql/mysql.log
Bu_jLT.yr8,y
[root@centos7-liyj /data]#cd mysql/
[root@centos7-liyj /data/mysql]#ll
total 110664
-rw-r----- 1 mysql mysql       56 May 10 10:26 auto.cnf
-rw------- 1 mysql mysql     1680 May 10 10:26 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 May 10 10:26 ca.pem
-rw-r--r-- 1 mysql mysql     1112 May 10 10:26 client-cert.pem
-rw------- 1 mysql mysql     1676 May 10 10:26 client-key.pem
-rw-r----- 1 mysql mysql      436 May 10 10:26 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 May 10 10:26 ibdata1
-rw-r----- 1 mysql mysql 50331648 May 10 10:26 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May 10 10:26 ib_logfile1
drwxr-x--- 2 mysql mysql     4096 May 10 10:26 mysql
-rw-r----- 1 mysql mysql     1108 May 10 10:26 mysql.log
drwxr-x--- 2 mysql mysql     8192 May 10 10:26 performance_schema
-rw------- 1 mysql mysql     1680 May 10 10:26 private_key.pem
-rw-r--r-- 1 mysql mysql      452 May 10 10:26 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 May 10 10:26 server-cert.pem
-rw------- 1 mysql mysql     1680 May 10 10:26 server-key.pem
drwxr-x--- 2 mysql mysql     8192 May 10 10:26 sys
[root@centos7-liyj /data/mysql]#cat mysql.log 
2022-05-10T02:26:08.549541Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-05-10T02:26:08.668742Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-05-10T02:26:08.689686Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-05-10T02:26:08.743917Z 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: 8d1ce2f2-d008-11ec-8556-005056399ee0.
2022-05-10T02:26:08.745068Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-05-10T02:26:09.353933Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-05-10T02:26:09.353947Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-05-10T02:26:09.354427Z 0 [Warning] CA certificate ca.pem is self signed.
2022-05-10T02:26:09.459455Z 1 [Note] A temporary password is generated for root@localhost: Bu_jLT.yr8,y
生成的数据文件和密码

方式2: 生成 root 空密码

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

准备服务脚本和启动

[root@centos7-liyj /data/mysql]#cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@centos7-liyj /data/mysql]#chkconfig --add mysqld

[root@centos7-liyj /data/mysql]#systemctl start mysqld
[root@centos7-liyj /data/mysql]#ss -antl
State      Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN     0      128                         *:22                                      *:*                  
LISTEN     0      100                 127.0.0.1:25                                      *:*                  
LISTEN     0      128                 127.0.0.1:6010                                    *:*                  
LISTEN     0      128                 127.0.0.1:6011                                    *:*                  
LISTEN     0      80                       [::]:3306                                 [::]:*                  
LISTEN     0      128                      [::]:22                                   [::]:*                  
LISTEN     0      100                     [::1]:25                                   [::]:*                  
LISTEN     0      128                     [::1]:6010                                 [::]:*                  
LISTEN     0      128                     [::1]:6011                                 [::]:*                  
端口3306

 

修改口令---修改前面生成的随机密码为指定密码
[root@centos7-liyj /data/mysql]#mysqladmin -uroot -p'Bu_jLT.yr8,y' password atech123456
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.

登录测试
[root@centos7-liyj /data/mysql]#mysql -uroot -patech123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> 

#修改前面生成的空密码为指定密码

mysqladmin -uroot   password atech123456

 



这篇关于Linux-安装-MySQL5.7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程