1、下载安装包【mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz】

https://dev.mysql.com/downloads/mysql/5.6.html#downloads

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

2、解压安装部署

[root@k8smaster01 mysql]# pwd
/data/mysql
[root@k8smaster01 mysql]# ls -lrt
total 394148
-rw-r--r-- 1 zhaiky zhaiky 403607456 Mar  1 21:48 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
[root@k8smaster01 mysql]# tar -xvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz   #解压软件包
[root@k8smaster01 support-files]# pwd
/data/mysql/mysql-5.6.47-linux-glibc2.12-x86_64/support-files
[root@k8smaster01 support-files]# cp my-default.cnf /etc/my.cnf  #拷贝配置文件
[root@k8smaster01 mysql]# ln -s /data/mysql/mysql-5.6.47-linux-glibc2.12-x86_64 /data/mysql/mysql  #建立软链接
[root@k8smaster01 mysql]# ls -lrt
total 394152
-rw-r--r--  1 zhaiky zhaiky 403607456 Mar  1 21:48 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x 13 root   root        4096 Mar  1 22:34 mysql-5.6.47-linux-glibc2.12-x86_64
lrwxrwxrwx  1 root   root          47 Mar  1 22:35 mysql -> /data/mysql/mysql-5.6.47-linux-glibc2.12-x86_64
[root@k8smaster01 mysql]# 
[root@k8smaster01 mysql]# more /etc/my.cnf  #修改后的配置文件
[mysqld] 
basedir=/data/mysql/mysql 
datadir=/data/mysql/mysql/data 
socket= /var/lib/mysql/mysql.sock 
user=zhaiky
port=3306 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
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 mysql]#
[root@k8smaster01 mysql]# chown -R zhaiky:zhaiky /data/mysql/ #修改mysql安装目录权限

3、数据库初始化

[zhaiky@k8smaster01 scripts]$ ./mysql_install_db --user=zhaiky
FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper  #缺失依赖
[zhaiky@k8smaster01 scripts]$ 
[root@k8smaster01 yum.repos.d]# yum -y install perl perl-devel
[root@k8smaster01 yum.repos.d]# yum -y install autoconf
[zhaiky@k8smaster01 ~]$ cd /data/mysql/mysql/scripts/
[zhaiky@k8smaster01 mysql]$ ./scripts/mysql_install_db --user=zhaiky
Installing MySQL system tables...2020-03-02 00:11:36 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-02 00:11:36 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-03-02 00:11:36 0 [Note] ./bin/mysqld (mysqld 5.6.47) starting as process 13102 ...
2020-03-02 00:11:36 13102 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-03-02 00:11:36 13102 [Note] InnoDB: The InnoDB memory heap is disabled
2020-03-02 00:11:36 13102 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-03-02 00:11:36 13102 [Note] InnoDB: Memory barrier is not used
2020-03-02 00:11:36 13102 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-03-02 00:11:36 13102 [Note] InnoDB: Using Linux native AIO
2020-03-02 00:11:36 13102 [Note] InnoDB: Using CPU crc32 instructions
2020-03-02 00:11:36 13102 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-03-02 00:11:36 13102 [Note] InnoDB: Completed initialization of buffer pool
2020-03-02 00:11:36 13102 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2020-03-02 00:11:36 13102 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2020-03-02 00:11:36 13102 [Note] InnoDB: Database physically writes the file full: wait...
2020-03-02 00:11:36 13102 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2020-03-02 00:11:36 13102 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2020-03-02 00:11:37 13102 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2020-03-02 00:11:37 13102 [Warning] InnoDB: New log files created, LSN=45781
2020-03-02 00:11:37 13102 [Note] InnoDB: Doublewrite buffer not found: creating new
2020-03-02 00:11:37 13102 [Note] InnoDB: Doublewrite buffer created
2020-03-02 00:11:37 13102 [Note] InnoDB: 128 rollback segment(s) are active.
2020-03-02 00:11:37 13102 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-03-02 00:11:37 13102 [Note] InnoDB: Foreign key constraint system tables created
2020-03-02 00:11:37 13102 [Note] InnoDB: Creating tablespace and datafile system tables.
2020-03-02 00:11:37 13102 [Note] InnoDB: Tablespace and datafile system tables created.
2020-03-02 00:11:37 13102 [Note] InnoDB: Waiting for purge to start
2020-03-02 00:11:37 13102 [Note] InnoDB: 5.6.47 started; log sequence number 0
2020-03-02 00:11:37 13102 [Note] RSA private key file not found: /data/mysql/mysql/data//private_key.pem. Some authentication plugins will not work.
2020-03-02 00:11:37 13102 [Note] RSA public key file not found: /data/mysql/mysql/data//public_key.pem. Some authentication plugins will not work.
2020-03-02 00:11:38 13102 [Note] Binlog end
2020-03-02 00:11:38 13102 [Note] InnoDB: FTS optimize thread exiting.
2020-03-02 00:11:38 13102 [Note] InnoDB: Starting shutdown...
2020-03-02 00:11:39 13102 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2020-03-02 00:11:39 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-03-02 00:11:39 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-03-02 00:11:39 0 [Note] ./bin/mysqld (mysqld 5.6.47) starting as process 13175 ...
2020-03-02 00:11:39 13175 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-03-02 00:11:39 13175 [Note] InnoDB: The InnoDB memory heap is disabled
2020-03-02 00:11:39 13175 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-03-02 00:11:39 13175 [Note] InnoDB: Memory barrier is not used
2020-03-02 00:11:39 13175 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-03-02 00:11:39 13175 [Note] InnoDB: Using Linux native AIO
2020-03-02 00:11:39 13175 [Note] InnoDB: Using CPU crc32 instructions
2020-03-02 00:11:39 13175 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-03-02 00:11:39 13175 [Note] InnoDB: Completed initialization of buffer pool
2020-03-02 00:11:39 13175 [Note] InnoDB: Highest supported file format is Barracuda.
2020-03-02 00:11:39 13175 [Note] InnoDB: 128 rollback segment(s) are active.
2020-03-02 00:11:39 13175 [Note] InnoDB: Waiting for purge to start
2020-03-02 00:11:39 13175 [Note] InnoDB: 5.6.47 started; log sequence number 1625977
2020-03-02 00:11:39 13175 [Note] RSA private key file not found: /data/mysql/mysql/data//private_key.pem. Some authentication plugins will not work.
2020-03-02 00:11:39 13175 [Note] RSA public key file not found: /data/mysql/mysql/data//public_key.pem. Some authentication plugins will not work.
2020-03-02 00:11:39 13175 [Note] Binlog end
2020-03-02 00:11:39 13175 [Note] InnoDB: FTS optimize thread exiting.
2020-03-02 00:11:39 13175 [Note] InnoDB: Starting shutdown...
2020-03-02 00:11:41 13175 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /data/mysql/mysql/bin/mysqladmin -u root password 'new-password'  #重置root密码
  /data/mysql/mysql/bin/mysqladmin -u root -h 192.168.23.100 password 'new-password'

Alternatively you can run:

  /data/mysql/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /data/mysql/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

4、数据库启动

[zhaiky@k8smaster01 bin]$ ./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root &
[1] 20523
[zhaiky@k8smaster01 bin]$ 200302 00:18:03 mysqld_safe Logging to '/data/mysql/mysql/mysqld.log'.
200302 00:18:03 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql/data

[zhaiky@k8smaster01 bin]$ 
[zhaiky@k8smaster01 mysql]$ more mysqld.log 
200302 00:18:03 mysqld_safe Logging to '/data/mysql/mysql/mysqld.log'.
200302 00:18:03 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql/data
2020-03-02 00:18:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp
 server option (see documentation for more details).
2020-03-02 00:18:04 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2020-03-02 00:18:04 0 [Note] /data/mysql/mysql/bin/mysqld (mysqld 5.6.47) starting as process 20735 ...
2020-03-02 00:18:04 20735 [Note] Plugin 'FEDERATED' is disabled.
2020-03-02 00:18:04 20735 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-03-02 00:18:04 20735 [Note] InnoDB: The InnoDB memory heap is disabled
2020-03-02 00:18:04 20735 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-03-02 00:18:04 20735 [Note] InnoDB: Memory barrier is not used
2020-03-02 00:18:04 20735 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-03-02 00:18:04 20735 [Note] InnoDB: Using Linux native AIO
2020-03-02 00:18:04 20735 [Note] InnoDB: Using CPU crc32 instructions
2020-03-02 00:18:04 20735 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-03-02 00:18:04 20735 [Note] InnoDB: Completed initialization of buffer pool
2020-03-02 00:18:04 20735 [Note] InnoDB: Highest supported file format is Barracuda.
2020-03-02 00:18:04 20735 [Note] InnoDB: 128 rollback segment(s) are active.
2020-03-02 00:18:04 20735 [Note] InnoDB: Waiting for purge to start
2020-03-02 00:18:04 20735 [Note] InnoDB: 5.6.47 started; log sequence number 1625987
2020-03-02 00:18:04 20735 [Warning] No existing UUID has been found, so we assume that this is the first time that this server ha
s been started. Generating a new UUID: 3b058d2d-5bd8-11ea-bf17-000c291c4997.
2020-03-02 00:18:04 20735 [Note] RSA private key file not found: /data/mysql/mysql/data//private_key.pem. Some authentication plu
gins will not work.
2020-03-02 00:18:04 20735 [Note] RSA public key file not found: /data/mysql/mysql/data//public_key.pem. Some authentication plugi
ns will not work.
2020-03-02 00:18:04 20735 [Note] Server hostname (bind-address): '*'; port: 3306
2020-03-02 00:18:04 20735 [Note] IPv6 is available.
2020-03-02 00:18:04 20735 [Note]   - '::' resolves to '::';
2020-03-02 00:18:04 20735 [Note] Server socket created on IP: '::'.
2020-03-02 00:18:04 20735 [Warning] 'user' entry 'root@k8smaster01' ignored in --skip-name-resolve mode.
2020-03-02 00:18:04 20735 [Warning] 'user' entry '@k8smaster01' ignored in --skip-name-resolve mode.
2020-03-02 00:18:04 20735 [Warning] 'proxies_priv' entry '@ root@k8smaster01' ignored in --skip-name-resolve mode.
2020-03-02 00:18:04 20735 [Note] Event Scheduler: Loaded 0 events
2020-03-02 00:18:04 20735 [Note] /data/mysql/mysql/bin/mysqld: ready for connections.
Version: '5.6.47'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)
[zhaiky@k8smaster01 mysql]$ 

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

[root@k8smaster01 mysql]# ln -s /data/mysql/mysql/bin/mysql /usr/bin   #将mysql命令添加到/usr/bin

[zhaiky@k8smaster01 bin]$ /data/mysql/mysql/bin/mysqladmin -u root -h 192.168.23.100 password '123456'
/data/mysql/mysql/bin/mysqladmin: connect to server at '192.168.23.100' failed
error: 'Host '192.168.23.100' is not allowed to connect to this MySQL server'
[zhaiky@k8smaster01 bin]$ /data/mysql/mysql/bin/mysqladmin -u root password '123456'
Warning: Using a password on the command line interface can be insecure.
[zhaiky@k8smaster01 bin]$ 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 3
Server version: 5.6.47 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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> 
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' with grant option;  #123456为你给新增权限用户设置的密码,%代表所有主机
Query OK, 0 rows affected (0.00 sec)

mysql> select Host,User,Password from user;
+-------------+------+-------------------------------------------+
| Host        | User | Password                                  |
+-------------+------+-------------------------------------------+
| localhost   | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| k8smaster01 | root |                                           |
| 127.0.0.1   | root |                                           |
| ::1         | root |                                           |
| localhost   |      |                                           |
| k8smaster01 |      |                                           |
| %           | root | *84AAC12F54AB666ECFC2A83C676908C8BBC381B1 |
| %           | test | *84AAC12F54AB666ECFC2A83C676908C8BBC381B1 |
+-------------+------+-------------------------------------------+
8 rows in set (0.00 sec)

mysql>

mysql> Flush privileges; #从mysql数据库的grant表中重新加载权限数据,因为MySQL把权限都放在cache中,所以在做完更改后需要重新加载。
Query OK, 0 rows affected (0.00 sec)

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐