mysql5.7安装

China☆狼群 提交于 2020-03-06 03:26:13

1、下载安装包【Percona-Server-5.7.25】

https://www.percona.com/downloads/Percona-Server-5.7/LATEST/

链接:https://pan.baidu.com/s/1ZvmX7IgNxGY0WhqA_ZC3pw 

 

2、解压安装部署

[root@k8smaster01 mysql]# pwd
/data/mysql
[root@k8smaster01 mysql]# tar -xvf Percona-Server-5.7.25-28-Linux.x86_64.ssl101.tar.gz    #解压软件包
[root@k8smaster01 mysql]# ls -lrt
total 446252
drwxrwxr-x 10 root   root        4096 Feb 18  2019 Percona-Server-5.7.25-28-Linux.x86_64.ssl101
-rw-r--r--  1 zhaiky zhaiky 456955915 Mar  2 14:01 Percona-Server-5.7.25-28-Linux.x86_64.ssl101.tar.gz
[root@k8smaster01 mysql]# ln -s Percona-Server-5.7.25-28-Linux.x86_64.ssl101 mysql   #建立软链接
[root@k8smaster01 mysql]# ls -lrt
total 446252
drwxrwxr-x 10 root   root        4096 Feb 18  2019 Percona-Server-5.7.25-28-Linux.x86_64.ssl101
-rw-r--r--  1 zhaiky zhaiky 456955915 Mar  2 14:01 Percona-Server-5.7.25-28-Linux.x86_64.ssl101.tar.gz
lrwxrwxrwx  1 root   root          44 Mar  2 14:10 mysql -> Percona-Server-5.7.25-28-Linux.x86_64.ssl101
[root@k8smaster01 mysql]# 
[root@k8smaster01 config]# pwd
/data/mysql/mysql/config
[root@k8smaster01 config]# more my.cnf  #修改后的配置文件
[mysqld] 
basedir=/data/mysql/mysql 
datadir=/data/mysql/mysql/data 
socket= /var/lib/mysql/mysql.sock 
user=zhaiky
port=3306 
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
character_set_server=utf8 
skip-name-resolve 
  
[mysqld_safe] 
log-error=/data/mysql/mysql/mysqld.log 
pid-file=/data/mysql/mysql/mysqld.pid 

[root@k8smaster01 config]# 
[root@k8smaster01 config]# chown -R zhaiky:zhaiky /data/mysql/ #修改mysql安装目录权限
 

3、数据库初始化

[zhaiky@k8smaster01 mysql]$ /data/mysql/mysql/bin/mysqld --initialize  --user=zhaiky --datadir=/data/mysql/mysql/data  --basedir=/data/mysql/mysql
2020-03-02T06:25:10.918888Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-02T06:25:10.919390Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-03-02T06:25:10.919397Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2020-03-02T06:25:14.057654Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-03-02T06:25:14.357433Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-02T06:25:14.439286Z 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: 93c20797-5c4e-11ea-9b82-000c291c4997.
2020-03-02T06:25:14.440845Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-03-02T06:25:14.630260Z 0 [Warning] CA certificate ca.pem is self signed.
2020-03-02T06:25:14.732161Z 1 [Note] A temporary password is generated for root@localhost: q(DPeUjmD9Dp
2020-03-02T06:25:15.899527Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:25:15.899550Z 1 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:25:15.899557Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:25:15.899568Z 1 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:25:15.899571Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:25:15.899578Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:25:15.899598Z 1 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:25:15.899603Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
[zhaiky@k8smaster01 mysql]$ 
 

4、数据库启动

[zhaiky@k8smaster01 bin]$ pwd
/data/mysql/mysql/bin
[zhaiky@k8smaster01 bin]$ ./mysqld_safe --defaults-file=/data/mysql/mysql/config/my.cnf --socket=/tmp/mysql.sock --user=root &
[1] 56015
[zhaiky@k8smaster01 bin]$  mysqld_safe Adding '/data/mysql/Percona-Server-5.7.25-28-Linux.x86_64.ssl101/lib/mysql/libjemalloc.so.1' to LD_PRELOAD for mysqld
2020-03-02T06:28:34.418166Z mysqld_safe Logging to '/data/mysql/mysql/mysqld.log'.
2020-03-02T06:28:34.477275Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql/data
[zhaiky@k8smaster01 bin]$ more /data/mysql/mysql/mysqld.log #启动日志
2020-03-02T06:28:34.418166Z mysqld_safe Logging to '/data/mysql/mysql/mysqld.log'.
2020-03-02T06:28:34.477275Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql/data
2020-03-02T06:28:34.713592Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_t
imestamp server option (see documentation for more details).
2020-03-02T06:28:34.713647Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be us
ed with strict mode. They will be merged with strict mode in a future release.
2020-03-02T06:28:34.713675Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are di
sabled
2020-03-02T06:28:34.713693Z 0 [Note] /data/mysql/mysql/bin/mysqld (mysqld 5.7.25-28) starting as process 56247 ...
2020-03-02T06:28:34.723053Z 0 [Note] InnoDB: PUNCH HOLE support available
2020-03-02T06:28:34.723128Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-03-02T06:28:34.723131Z 0 [Note] InnoDB: Uses event mutexes
2020-03-02T06:28:34.723134Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2020-03-02T06:28:34.723136Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2020-03-02T06:28:34.723139Z 0 [Note] InnoDB: Using Linux native AIO
2020-03-02T06:28:34.725082Z 0 [Note] InnoDB: Number of pools: 1
2020-03-02T06:28:34.725202Z 0 [Note] InnoDB: Using CPU crc32 instructions
2020-03-02T06:28:34.727884Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2020-03-02T06:28:34.739550Z 0 [Note] InnoDB: Completed initialization of buffer pool
2020-03-02T06:28:34.749276Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be chan
ged. See the man page of setpriority().
2020-03-02T06:28:34.762714Z 0 [Note] InnoDB: Crash recovery did not find the parallel doublewrite buffer at /data/mysql/Percona-S
erver-5.7.25-28-Linux.x86_64.ssl101/data/xb_doublewrite
2020-03-02T06:28:34.764690Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2020-03-02T06:28:34.794367Z 0 [Note] InnoDB: Created parallel doublewrite buffer at /data/mysql/Percona-Server-5.7.25-28-Linux.x8
6_64.ssl101/data/xb_doublewrite, size 3932160 bytes
2020-03-02T06:28:34.812161Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-03-02T06:28:34.812305Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait
 ...
2020-03-02T06:28:35.005897Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2020-03-02T06:28:35.008240Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2020-03-02T06:28:35.008283Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2020-03-02T06:28:35.025205Z 0 [Note] InnoDB: Waiting for purge to start
2020-03-02T06:28:35.075820Z 0 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.7.25-28 started; log sequence number 25294
23
2020-03-02T06:28:35.084031Z 0 [Note] Plugin 'FEDERATED' is disabled.
2020-03-02T06:28:35.091472Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/Percona-Server-5.7.25-28-Linux.x86_64.ssl101
/data/ib_buffer_pool
2020-03-02T06:28:35.118653Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200302 14:28:35
2020-03-02T06:28:35.170441Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL sup
port using them.
2020-03-02T06:28:35.170483Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2020-03-02T06:28:35.172070Z 0 [Warning] CA certificate ca.pem is self signed.
2020-03-02T06:28:35.172142Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2020-03-02T06:28:35.172296Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2020-03-02T06:28:35.172336Z 0 [Note] IPv6 is available.
2020-03-02T06:28:35.172343Z 0 [Note]   - '::' resolves to '::';
2020-03-02T06:28:35.172363Z 0 [Note] Server socket created on IP: '::'.
2020-03-02T06:28:35.177449Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:28:35.177526Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:28:35.177540Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:28:35.177563Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mo
de.
2020-03-02T06:28:35.177568Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:28:35.177579Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:28:35.179171Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:28:35.179240Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
2020-03-02T06:28:35.185963Z 0 [Note] Event Scheduler: Loaded 0 events
2020-03-02T06:28:35.187691Z 0 [Note] /data/mysql/mysql/bin/mysqld: ready for connections.
Version: '5.7.25-28'  socket: '/tmp/mysql.sock'  port: 3306  Percona Server (GPL), Release 28, Revision c335905
 

5、客户端连接【修改root密码和支持远程登录】

[root@k8smaster01 config]# ln -s /data/mysql/mysql/bin/mysql /usr/bin
[zhaiky@k8smaster01 ~]$ mysql -uroot -p  #mysql -h 主机名 -u 用户名 -p
参数说明:
-h : 指定客户端所要登录的 MySQL 主机名, 登录本机(localhost 或 127.0.0.1)该参数可以省略;
-u : 登录的用户名;
-p : 告诉服务器将会使用一个密码来登录, 如果所要登录的用户名密码为空, 可以忽略此选项。

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25-28
Copyright (c) 2009-2019 Percona LLC and/or its affiliates
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> SET PASSWORD = PASSWORD('123456'); #重置密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> 
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; #永不失效
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> update user set host = '%' where user = 'root'; #开启远程登录
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

 

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> Flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER 'zhaiky'@'%' IDENTIFIED BY '123456';  #创建用户
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'zhaiky'@'%' identified by '123456' with grant option; #赋权
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges; #生效
Query OK, 0 rows affected (0.01 sec)
 mysql> select user,authentication_string,host from user;   #查看用户密码
+---------------+-------------------------------------------+-----------+
| user          | authentication_string                     | host      |
+---------------+-------------------------------------------+-----------+
| root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost |
| zhaiky        | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | %         |
| root          | *84AAC12F54AB666ECFC2A83C676908C8BBC381B1 | %         |
+---------------+-------------------------------------------+-----------+
5 rows in set (0.00 sec)
mysql> select password ('12345678'); #明文加密
+-------------------------------------------+
| password ('12345678')                     |
+-------------------------------------------+
| *84AAC12F54AB666ECFC2A83C676908C8BBC381B1 |
+-------------------------------------------+
1 row in set, 1 warning (0.01 sec)
[zhaiky@k8smaster02 bin]$ ./mysqladmin -h192.168.23.101 -uroot -p123456 -S /var/lib/mysql/mysql.sock shutdown #shutdown关闭mysql服务 -p(小p) 密码
-P(大P) 端口
-h 连接主机
-u 用户
-S socket文件

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[zhaiky@k8smaster02 bin]$ 2020-03-02T12:19:51.340968Z mysqld_safe mysqld from pid file /data/mysql/mysql/mysqld.pid ended
[zhaiky@k8smaster02 bin]$

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!