CentOS 7.0 环境下MySQL安装教程

MySQL的安装教程多而杂,很多都过时了,安装过程不仅繁琐,而且还出现很多莫名其妙测问题。基于种种原因,我萌生了写MySQL安装教程想法,下边就是我写的快速安装MySQL服务器的两种方法,每条命令都附带了操作示例,傻瓜式的教程,希望对那些想要安装MySQL的小伙伴有帮助。废话不多下,直接上教程。

  • 安装环境:CentOS 7.5 64位,安装MySQL!

通过压缩文件方式安装MySQL

从MySQL官网下载的rpm安装包,文件名如下:MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar,这个就不做过多的解释了,需要的可以自行从官网下载
由于我得系统是CentOS 7.5.x的,所以我选择的操作系统和系统版本是:Red Hat Enterprise Linux / Oracle Linux和Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
如果要选择以前的老版本,只需要点击右边的 Looking for previous GA versions? 即可。

1.解压安装包

  • 进入MySQL 5.7.9软件包所在的路径,执行命令如下:
tar -xvf MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar
  • 操作示例:
[root@54lxb ~]# cd /home
[root@54lxb home]# ll
total 410208
-rw-r--r-- 1 root root 243793920 Nov 16 15:45 MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar
[root@54lxb home]# tar -xvf MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar 
MySQL-client-5.6.42-1.el7.x86_64.rpm
MySQL-server-5.6.42-1.el7.x86_64.rpm
MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm
MySQL-shared-5.6.42-1.el7.x86_64.rpm
MySQL-test-5.6.42-1.el7.x86_64.rpm
MySQL-embedded-5.6.42-1.el7.x86_64.rpm
MySQL-devel-5.6.42-1.el7.x86_64.rpm
[root@54lxb home]# ll
total 648292
-rw-r--r-- 1 root root  243793920 Nov 16 15:45 MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415  20454728 Sep 11 17:03 MySQL-client-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   3557640 Sep 11 17:03 MySQL-devel-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  92767812 Sep 11 17:03 MySQL-embedded-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  62472416 Sep 11 17:04 MySQL-server-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2120876 Sep 11 17:04 MySQL-shared-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2299660 Sep 11 17:04 MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  60112712 Sep 11 17:04 MySQL-test-5.6.42-1.el7.x86_64.rpm

2.卸载已装MySQL

  • 查看是否已经安装过MySQL,执行如下命令:
rpm -qa | grep -i mysql
  • 操作示例:
[root@54lxb ~]# rpm -qa|grep -i mysql
MySQL-devel-5.6.42-1.el7.x86_64
MySQL-embedded-5.6.42-1.el7.x86_64
MySQL-shared-compat-5.6.42-1.el7.x86_64
MySQL-client-5.6.42-1.el7.x86_64
MySQL-shared-5.6.42-1.el7.x86_64
MySQL-server-5.6.42-1.el7.x86_64
[root@54lxb ~]# 

  • 卸载已安装MySQL,执行命令如下:
rpm -e --nodeps package name
  • 操作示例:
[root@54lxb ~]# rpm -e --nodeps MySQL-devel-5.6.42-1.el7.x86_64
[root@54lxb ~]# 

卸载完成后,重新执行rpm -qa | grep -i mysql,看看是否已完全卸载已安装MySQL。

3.添加用户组:

  • 添加用户组,执行命令如下:
groupadd mysql
useradd -r -g mysql mysql
  • 操作示例:
[root@54lxb ~]# groupadd mysql
[root@54lxb ~]# useradd -r -g mysql mysql
[root@54lxb ~]# 

4.按顺序安装安装包

  • 按顺序安装安装包,执行命令如下:
rpm -ivh MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm

rpm -ivh MySQL-devel-5.6.42-1.el7.x86_64.rpm

rpm -ivh MySQL-client-5.6.42-1.el7.x86_64.rpm

rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm

rpm -ivh MySQL-shared-5.6.42-1.el7.x86_64.rpm

rpm -ivh MySQL-embedded-5.6.42-1.el7.x86_64.rpm
  • 操作示例:
[root@54lxb home]# rpm -ivh MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-shared-compat-5.6.42-1.el7 ################################# [100%]
[root@54lxb home]# rpm -ivh MySQL-devel-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-devel-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-devel-5.6.42-1.el7         ################################# [100%]
[root@54lxb home]# rpm -ivh MySQL-client-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-client-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-client-5.6.42-1.el7        ################################# [100%]
[root@54lxb home]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-server-5.6.42-1.el7        ################################# [100%]
[root@54lxb home]# rpm -ivh MySQL-shared-5.6.42-1.el7.x86_64.rpm
warning: MySQL-shared-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-shared-5.6.42-1.el7        ################################# [100%]
[root@54lxb home]# rpm -ivh MySQL-embedded-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-embedded-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-embedded-5.6.42-1.el7        ################################# [100%]
[root@54lxb home]# 

在安装 MySQL-server-5.6.42-1.el7.x86_64.rpm 时可能遇到如下错误:

[root@54lxb home]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
  libnuma.so.1()(64bit) is needed by MySQL-server-5.6.42-1.el7.x86_64
  libnuma.so.1(libnuma_1.1)(64bit) is needed by MySQL-server-5.6.42-1.el7.x86_64
  libnuma.so.1(libnuma_1.2)(64bit) is needed by MySQL-server-5.6.42-1.el7.x86_64

[root@54lxb home]# 

根据提示可知,缺少安装MySQL Server的依赖,只需要执行如下命令安装缺少依赖即可:

yum install numactl-libs

在重新执行安装mysql server 的命令之前,必须先卸载已安装的 mysql server,不然会提示,MySQL server已经安装了。

[root@54lxb home]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
    package MySQL-server-5.6.42-1.el7.x86_64.rpm is already installed
[root@54lxb home]# 
[root@54lxb home]# rpm -e MySQL-server-5.6.42-1.el7.x86_64
[root@54lxb home]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm 
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-server-5.6.42-1.el7        ################################# [100%]
[root@54lxb home]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-server-5.6.42-1.el7        ################################# [100%]
2018-11-20 13:54:16 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:54:16 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:54:16 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2468 ...
2018-11-20 13:54:16 2468 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:54:16 2468 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:54:16 2468 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:54:16 2468 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:54:16 2468 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:54:16 2468 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:54:16 2468 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:54:16 2468 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:54:16 2468 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:54:16 2468 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-11-20 13:54:16 2468 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-11-20 13:54:16 2468 [Note] InnoDB: Database physically writes the file full: wait...
2018-11-20 13:54:16 2468 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-11-20 13:54:17 2468 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-11-20 13:54:17 2468 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-11-20 13:54:17 2468 [Warning] InnoDB: New log files created, LSN=45781
2018-11-20 13:54:17 2468 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-11-20 13:54:17 2468 [Note] InnoDB: Doublewrite buffer created
2018-11-20 13:54:17 2468 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:54:17 2468 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-20 13:54:17 2468 [Note] InnoDB: Foreign key constraint system tables created
2018-11-20 13:54:17 2468 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-11-20 13:54:17 2468 [Note] InnoDB: Tablespace and datafile system tables created.
2018-11-20 13:54:17 2468 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:54:17 2468 [Note] InnoDB: 5.6.42 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2018-11-20 13:54:17 2468 [Note] Binlog end
2018-11-20 13:54:17 2468 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:54:17 2468 [Note] InnoDB: Starting shutdown...
2018-11-20 13:54:19 2468 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2018-11-20 13:54:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:54:19 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:54:19 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2493 ...
2018-11-20 13:54:19 2493 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:54:19 2493 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:54:19 2493 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:54:19 2493 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:54:19 2493 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:54:19 2493 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:54:19 2493 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:54:19 2493 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:54:19 2493 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:54:19 2493 [Note] InnoDB: Highest supported file format is Barracuda.
2018-11-20 13:54:19 2493 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:54:19 2493 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:54:19 2493 [Note] InnoDB: 5.6.42 started; log sequence number 1625977
2018-11-20 13:54:19 2493 [Note] Binlog end
2018-11-20 13:54:19 2493 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:54:19 2493 [Note] InnoDB: Starting shutdown...
2018-11-20 13:54:21 2493 [Note] InnoDB: Shutdown completed; log sequence number 1625987




A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

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 /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

[root@54lxb home]#

在安装完MySQL-Server后,我们不难发现其中有一句话:

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

这句话告诉我们,MySQL已经为我们生成了一个root用户,密码存在’/root/.mysql_secret’文件中。

5.更改mysql数据库目录的所属用户及其所属组

  • 查询mysql的安装目录信息,执行命令如下:
whereis mysql
  • 操作示例:
[root@54lxb home]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@54lxb home]# 
  • 实现目录的所属用户组和用户的变更

一般mysql的默认数据目录则是:/var/lib/mysql

chown mysql:mysql /var/lib/mysql -R
  • 操作示例:
[root@54lxb home]# chown mysql:mysql /var/lib/mysql -R
[root@54lxb home]# 

6.添加自启动服务

添加自启动服务,执行命令如下:

chkconfig --add mysql
chkconfig mysql on
  • 操作示例:
[root@54lxb home]# chkconfig --add mysql
[root@54lxb home]# chkconfig mysql on
[root@54lxb home]# 

7.添加配置文件

  • 查找my-default.cnf配置文件的所在路径,命令如下:
find / -name my-default.cnf
  • 操作示例:
[root@54lxb home]# find / -name my-default.cnf
/usr/share/doc/MySQL-server-5.6.42/my-default.cnf
/usr/share/mysql/my-default.cnf
[root@54lxb home]# 
  • 复制配置文件,命令如下:
cd /usr/share/mysql/
cp my-default.cnf /etc/my.cnf
  • 操作示例:
[root@54lxb home]# cd /usr/share/mysql/
[root@54lxb mysql]# cp my-default.cnf /etc/my.cnf
[root@54lxb mysql]# 

8.初始化mysql数据库

  • 初始化mysql数据库,命令如下:
mysql_install_db --user=mysql
  • 操作示例:
[root@54lxb mysql]# mysql_install_db --user=mysql
Installing MySQL system tables...2018-11-20 13:57:42 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:57:42 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:57:42 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2906 ...
2018-11-20 13:57:42 2906 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:57:42 2906 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:57:42 2906 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:57:42 2906 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:57:42 2906 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:57:42 2906 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:57:42 2906 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:57:42 2906 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:57:42 2906 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:57:42 2906 [Note] InnoDB: Highest supported file format is Barracuda.
2018-11-20 13:57:42 2906 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:57:42 2906 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:57:42 2906 [Note] InnoDB: 5.6.42 started; log sequence number 1625987
2018-11-20 13:57:42 2906 [Note] Binlog end
2018-11-20 13:57:42 2906 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:57:42 2906 [Note] InnoDB: Starting shutdown...
2018-11-20 13:57:44 2906 [Note] InnoDB: Shutdown completed; log sequence number 1625997
OK

Filling help tables...2018-11-20 13:57:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:57:44 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:57:44 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2930 ...
2018-11-20 13:57:44 2930 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:57:44 2930 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:57:44 2930 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:57:44 2930 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:57:44 2930 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:57:44 2930 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:57:44 2930 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:57:44 2930 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:57:44 2930 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:57:44 2930 [Note] InnoDB: Highest supported file format is Barracuda.
2018-11-20 13:57:44 2930 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:57:44 2930 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:57:44 2930 [Note] InnoDB: 5.6.42 started; log sequence number 1625997
2018-11-20 13:57:44 2930 [Note] Binlog end
2018-11-20 13:57:44 2930 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:57:44 2930 [Note] InnoDB: Starting shutdown...
2018-11-20 13:57:46 2930 [Note] InnoDB: Shutdown completed; log sequence number 1626007
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:

  /usr/bin/mysqladmin -u root password 'new-password'
  /usr/bin/mysqladmin -u root -h 54lxb password 'new-password'

Alternatively you can run:

  /usr/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 /usr ; /usr/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

WARNING: Found existing config file /usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/my-new.cnf,
please compare it with your file and take the changes you need.

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

[root@54lxb mysql]# 

9.启动mysql服务

  • 启动mysql服务,命令如下:
service mysql start
  • 操作示例:
[root@54lxb mysql]# service mysql start
Starting MySQL.Logging to '/var/lib/mysql/54lxb.err'.
 SUCCESS! 
[root@54lxb mysql]# 

使用mysql -u root -p命令登录数据库,测试是否安装成功,如果出现让我们输入密码的提示,那就证明我们安装成功了!

10.修改root账户密码,登录数据库

  • 修改root账户密码,命令如下:

该命令需要登入MySQL才能设置,至于MySQL的登入密码,我们在安装MySQL的时候就告诉我们了。

cat /root/.mysql_secret
mysql -u root -p
mysql> SET PASSWORD = PASSWORD('123456');
  • 操作示例:
[root@54lxb mysql]# cd /root
[root@54lxb ~]# ls -a
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .cache  .config  .cshrc  .mysql_secret  .oracle_jre_usage  .pip  .pydistutils.cfg  .ssh  .tcshrc
[root@bright ~]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2015-03-27 23:12:10: Jj+FTiqvyrF
[root@54lxb ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.42

Copyright (c) 2000, 2018, 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 (0.02 sec)

mysql> exit
Bye
[root@54lxb ~]#

现在我们已经把MySQL的登录密码改为123456啦;

  • 登录数据库,测试是否成功,命令如下:
shell> mysql -u root -p
  • 操作示例:
[root@54lxb ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> exit
Bye
[root@54lxb ~]#

至此,mysql5.6.34安装工作完成,其他优化配置等工作请参考其他资料进行相关设置。

参考文章



安装过程命令执行如下:

[root@54lxb ~]# cd /home
[root@54lxb home]# ll -a
total 410120
drwxr-xr-x.  2 root root      4096 Nov 20 13:36 .
dr-xr-xr-x. 19 root root      4096 Nov 20 13:47 ..
-rw-r--r--   1 root root 176154027 Nov 16 13:05 jdk-8u191-linux-x64.rpm
-rw-r--r--   1 root root 243793920 Nov 16 15:45 MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar
[root@54lxb home]# ls -a
.  ..  jdk-8u191-linux-x64.rpm  MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar
[root@54lxb home]# rpm -ivh jdk-8u191-linux-x64.rpm 
warning: jdk-8u191-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk1.8-2000:1.8.0_191-fcs        ################################# [100%]
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...
[root@54lxb home]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
[root@54lxb home]# tar -xvf MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar 
MySQL-client-5.6.42-1.el7.x86_64.rpm
MySQL-server-5.6.42-1.el7.x86_64.rpm
MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm
MySQL-shared-5.6.42-1.el7.x86_64.rpm
MySQL-test-5.6.42-1.el7.x86_64.rpm
MySQL-embedded-5.6.42-1.el7.x86_64.rpm
MySQL-devel-5.6.42-1.el7.x86_64.rpm
[root@54lxb home]# mkdir MySQL-5.6.42-1.el7.x86_64.rpm-bundle
[root@54lxb home]# mv MySQL*.rpm /home/MySQL-5.6.42-1.el7.x86_64.rpm-bundle
[root@54lxb home]# ll
total 410116
-rw-r--r-- 1 root root 176154027 Nov 16 13:05 jdk-8u191-linux-x64.rpm
drwxr-xr-x 2 root root      4096 Nov 20 13:49 MySQL-5.6.42-1.el7.x86_64.rpm-bundle
-rw-r--r-- 1 root root 243793920 Nov 16 15:45 MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar
[root@54lxb home]# cd MySQL-5.6.42-1.el7.x86_64.rpm-bundle/
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# ll
total 238084
-rw-r--r-- 1 7155 31415 20454728 Sep 11 17:03 MySQL-client-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  3557640 Sep 11 17:03 MySQL-devel-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 92767812 Sep 11 17:03 MySQL-embedded-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 62472416 Sep 11 17:04 MySQL-server-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  2120876 Sep 11 17:04 MySQL-shared-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  2299660 Sep 11 17:04 MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 60112712 Sep 11 17:04 MySQL-test-5.6.42-1.el7.x86_64.rpm
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -qa | grep -i mysql
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# groupadd mysql
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# useradd -r -g mysql mysql
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm
warning: MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	mariadb-libs is obsoleted by MySQL-shared-compat-5.6.42-1.el7.x86_64
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -qa | grep maridb*
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -qa | grep mariadb*
mariadb-libs-5.5.56-2.el7.x86_64
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -e --nodeps mariadb-libs-*
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm
warning: MySQL-shared-compat-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-shared-compat-5.6.42-1.el7 ################################# [100%]
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-devel-5.6.42-1.el7.x86_64.rpm
warning: MySQL-devel-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-devel-5.6.42-1.el7         ################################# [100%]
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-client-5.6.42-1.el7.x86_64.rpm
warning: MySQL-client-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-client-5.6.42-1.el7        ################################# [100%]
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	libnuma.so.1()(64bit) is needed by MySQL-server-5.6.42-1.el7.x86_64
	libnuma.so.1(libnuma_1.1)(64bit) is needed by MySQL-server-5.6.42-1.el7.x86_64
	libnuma.so.1(libnuma_1.2)(64bit) is needed by MySQL-server-5.6.42-1.el7.x86_64
	perl(Data::Dumper) is needed by MySQL-server-5.6.42-1.el7.x86_64
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]#  yum install numactl-libs
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel                                                                                                                                                                                                                                                              12706/12706
Resolving Dependencies
--> Running transaction check
---> Package numactl-libs.x86_64 0:2.0.9-7.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                               Arch                                                            Version                                                              Repository                                                   Size
==============================================================================================================================================================================================================================================================================
Installing:
 numactl-libs                                                          x86_64                                                          2.0.9-7.el7                                                          os                                                           29 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  1 Package

Total download size: 29 k
Installed size: 50 k
Is this ok [y/d/N]: y
Downloading packages:
numactl-libs-2.0.9-7.el7.x86_64.rpm                                                                                                                                                                                                                    |  29 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
  Installing : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                                                                                                                            1/1 
  Verifying  : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                                                                                                                            1/1 

Installed:
  numactl-libs.x86_64 0:2.0.9-7.el7                                                                                                                                                                                                                                           

Complete!
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	perl(Data::Dumper) is needed by MySQL-server-5.6.42-1.el7.x86_64
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# yum -y install autoconf
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch
--> Processing Dependency: perl(Data::Dumper) for package: autoconf-2.69-11.el7.noarch
--> Running transaction check
---> Package m4.x86_64 0:1.4.16-10.el7 will be installed
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
 Package                                                                 Arch                                                          Version                                                                Repository                                                 Size
==============================================================================================================================================================================================================================================================================
Installing:
 autoconf                                                                noarch                                                        2.69-11.el7                                                            os                                                        701 k
Installing for dependencies:
 m4                                                                      x86_64                                                        1.4.16-10.el7                                                          os                                                        256 k
 perl-Data-Dumper                                                        x86_64                                                        2.145-3.el7                                                            os                                                         47 k

Transaction Summary
==============================================================================================================================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 1.0 M
Installed size: 2.8 M
Downloading packages:
(1/3): autoconf-2.69-11.el7.noarch.rpm                                                                                                                                                                                                                 | 701 kB  00:00:00     
(2/3): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                                                                                                                                                                         |  47 kB  00:00:00     
(3/3): m4-1.4.16-10.el7.x86_64.rpm                                                                                                                                                                                                                     | 256 kB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                         5.6 MB/s | 1.0 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : m4-1.4.16-10.el7.x86_64                                                                                                                                                                                                                                    1/3 
  Installing : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                                                                                                                        2/3 
  Installing : autoconf-2.69-11.el7.noarch                                                                                                                                                                                                                                3/3 
  Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                                                                                                                        1/3 
  Verifying  : m4-1.4.16-10.el7.x86_64                                                                                                                                                                                                                                    2/3 
  Verifying  : autoconf-2.69-11.el7.noarch                                                                                                                                                                                                                                3/3 

Installed:
  autoconf.noarch 0:2.69-11.el7                                                                                                                                                                                                                                               

Dependency Installed:
  m4.x86_64 0:1.4.16-10.el7                                 perl-Data-Dumper.x86_64 0:2.145-3.el7                                                                                                      

Complete!
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-server-5.6.42-1.el7.x86_64.rpm
warning: MySQL-server-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-server-5.6.42-1.el7        ################################# [100%]
2018-11-20 13:54:16 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. 
Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:54:16 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:54:16 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2468 ...
2018-11-20 13:54:16 2468 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:54:16 2468 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:54:16 2468 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:54:16 2468 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:54:16 2468 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:54:16 2468 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:54:16 2468 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:54:16 2468 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:54:16 2468 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:54:16 2468 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2018-11-20 13:54:16 2468 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2018-11-20 13:54:16 2468 [Note] InnoDB: Database physically writes the file full: wait...
2018-11-20 13:54:16 2468 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2018-11-20 13:54:17 2468 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-11-20 13:54:17 2468 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-11-20 13:54:17 2468 [Warning] InnoDB: New log files created, LSN=45781
2018-11-20 13:54:17 2468 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-11-20 13:54:17 2468 [Note] InnoDB: Doublewrite buffer created
2018-11-20 13:54:17 2468 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:54:17 2468 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-20 13:54:17 2468 [Note] InnoDB: Foreign key constraint system tables created
2018-11-20 13:54:17 2468 [Note] InnoDB: Creating tablespace and datafile system tables.
2018-11-20 13:54:17 2468 [Note] InnoDB: Tablespace and datafile system tables created.
2018-11-20 13:54:17 2468 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:54:17 2468 [Note] InnoDB: 5.6.42 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2018-11-20 13:54:17 2468 [Note] Binlog end
2018-11-20 13:54:17 2468 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:54:17 2468 [Note] InnoDB: Starting shutdown...
2018-11-20 13:54:19 2468 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2018-11-20 13:54:19 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. 
Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:54:19 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:54:19 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2493 ...
2018-11-20 13:54:19 2493 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:54:19 2493 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:54:19 2493 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:54:19 2493 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:54:19 2493 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:54:19 2493 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:54:19 2493 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:54:19 2493 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:54:19 2493 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:54:19 2493 [Note] InnoDB: Highest supported file format is Barracuda.
2018-11-20 13:54:19 2493 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:54:19 2493 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:54:19 2493 [Note] InnoDB: 5.6.42 started; log sequence number 1625977
2018-11-20 13:54:19 2493 [Note] Binlog end
2018-11-20 13:54:19 2493 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:54:19 2493 [Note] InnoDB: Starting shutdown...
2018-11-20 13:54:21 2493 [Note] InnoDB: Shutdown completed; log sequence number 1625987




A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

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 /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-shared-5.6.42-1.el7.x86_64.rpm
warning: MySQL-shared-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-shared-5.6.42-1.el7        ################################# [100%]
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# rpm -ivh MySQL-embedded-5.6.42-1.el7.x86_64.rpm
warning: MySQL-embedded-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:MySQL-embedded-5.6.42-1.el7      ################################# [100%]
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# chown mysql:mysql /var/lib/mysql -R
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# chkconfig --add mysql
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# chkconfig mysql on
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# find / -name my-default.cnf
/usr/share/mysql/my-default.cnf
/usr/share/doc/MySQL-server-5.6.42/my-default.cnf
[root@54lxb MySQL-5.6.42-1.el7.x86_64.rpm-bundle]# cd /usr/share/mysql/
[root@54lxb mysql]# cp my-default.cnf /etc/my.cnf
[root@54lxb mysql]# mysql_install_db --user=mysql
Installing MySQL system tables...2018-11-20 13:57:42 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. 
Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:57:42 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:57:42 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2906 ...
2018-11-20 13:57:42 2906 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:57:42 2906 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:57:42 2906 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:57:42 2906 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:57:42 2906 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:57:42 2906 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:57:42 2906 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:57:42 2906 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:57:42 2906 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:57:42 2906 [Note] InnoDB: Highest supported file format is Barracuda.
2018-11-20 13:57:42 2906 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:57:42 2906 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:57:42 2906 [Note] InnoDB: 5.6.42 started; log sequence number 1625987
2018-11-20 13:57:42 2906 [Note] Binlog end
2018-11-20 13:57:42 2906 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:57:42 2906 [Note] InnoDB: Starting shutdown...
2018-11-20 13:57:44 2906 [Note] InnoDB: Shutdown completed; log sequence number 1625997
OK

Filling help tables...2018-11-20 13:57:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. 
Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-20 13:57:44 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-11-20 13:57:44 0 [Note] /usr/sbin/mysqld (mysqld 5.6.42) starting as process 2930 ...
2018-11-20 13:57:44 2930 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-11-20 13:57:44 2930 [Note] InnoDB: The InnoDB memory heap is disabled
2018-11-20 13:57:44 2930 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-11-20 13:57:44 2930 [Note] InnoDB: Memory barrier is not used
2018-11-20 13:57:44 2930 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-11-20 13:57:44 2930 [Note] InnoDB: Using Linux native AIO
2018-11-20 13:57:44 2930 [Note] InnoDB: Using CPU crc32 instructions
2018-11-20 13:57:44 2930 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-11-20 13:57:44 2930 [Note] InnoDB: Completed initialization of buffer pool
2018-11-20 13:57:44 2930 [Note] InnoDB: Highest supported file format is Barracuda.
2018-11-20 13:57:44 2930 [Note] InnoDB: 128 rollback segment(s) are active.
2018-11-20 13:57:44 2930 [Note] InnoDB: Waiting for purge to start
2018-11-20 13:57:44 2930 [Note] InnoDB: 5.6.42 started; log sequence number 1625997
2018-11-20 13:57:44 2930 [Note] Binlog end
2018-11-20 13:57:44 2930 [Note] InnoDB: FTS optimize thread exiting.
2018-11-20 13:57:44 2930 [Note] InnoDB: Starting shutdown...
2018-11-20 13:57:46 2930 [Note] InnoDB: Shutdown completed; log sequence number 1626007
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:

  /usr/bin/mysqladmin -u root password 'new-password'
  /usr/bin/mysqladmin -u root -h 54lxb password 'new-password'

Alternatively you can run:

  /usr/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 /usr ; /usr/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

WARNING: Found existing config file /usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/my-new.cnf,
please compare it with your file and take the changes you need.

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

[root@54lxb mysql]# service mysql start
Starting MySQL.Logging to '/var/lib/mysql/54lxb.err'.
 SUCCESS! 
[root@54lxb mysql]# 

CentOS7 yum 安装与配置MySQL5.7

1、配置YUM源

在MySQL官网中下载YUM源rpm安装包:https://dev.mysql.com/downloads/repo/yum/

  • 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  • 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
  • 检查mysql源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"

2、安装MySQL

shell> yum install mysql-community-server

3、启动MySQL服务并查看启动状态

  • 启动MySQL服务
shell> systemctl start mysqld
  • 查看MySQL的启动状态
shell> systemctl status mysqld

4、开机启动

shell> systemctl enable mysqld
shell> systemctl daemon-reload

5、修改root本地登录密码

  • 查看mysql安装后的默认密码
shell> grep 'temporary password' /var/log/mysqld.log

操作示例:

[root@54lxb ~]#  grep 'temporary password' /var/log/mysqld.log
2018-11-21T15:03:45.219251Z 1 [Note] A temporary password is generated for root@localhost: Jj+FTiqvyrF
[root@54lxb ~]# 
  • 修改root本地登录密码

修改密码语句 ALTER 和 SET 任选其一即可;

shell> mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
mysql> SET password for 'root'@'localhost'=password('MyNewPass4!');

操作示例:

[root@54lxb ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.42

Copyright (c) 2000, 2018, 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 (0.02 sec)

mysql> exit
Bye
[root@54lxb ~]#

注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误。

  • 通过msyql环境变量可以查看密码策略的相关信息:
mysql> show variables like '%password%';

MySQL官网密码策略详细说明:MySQL 5.6 Reference Manual Password Validation Plugin Options and Variables

  • 修改密码策略

在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略,选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件validate_password_policy=0。如果不需要密码策略,添加my.cnf文件中添加配置禁用即可:validate_password = off,重新启动mysql服务使配置生效:

  • 重新启动mysql服
shell> systemctl restart mysqld

6、忘记MySQL密码解决办法

默认配置文件路径:

  • 配置文件:/etc/my.cnf

  • 日志文件:/var/log//var/log/mysqld.log

  • 服务启动脚本:/usr/lib/systemd/system/mysqld.service

  • socket文件:/var/run/mysqld/mysqld.pid

  • 修改配置文件

在配置文件中的[mysqld]的段中加上一句:skip-grant-tables保存并且退出vi。

  • 登录MySQL,设置新密码
shell> mysql  -u root

mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';

mysql> flush privileges

参考文章



安装过程命令执行如下:

[root@54lxb ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
--2018-11-21 10:48:47--  http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm [following]
--2018-11-21 10:48:47--  https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm [following]
--2018-11-21 10:48:48--  https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 173.223.141.174
Connecting to repo.mysql.com (repo.mysql.com)|173.223.141.174|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9116 (8.9K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-8.noarch.rpm’

100%[==================================================================================================================================================>] 9,116       --.-K/s   in 0.001s  

2018-11-21 10:48:50 (7.45 MB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116]

[root@54lxb ~]#  yum localinstall mysql57-community-release-el7-8.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
Marking mysql57-community-release-el7-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================
 Package                                            Arch                            Version                          Repository                                                        Size
============================================================================================================================================================================================
Installing:
 mysql57-community-release                          noarch                          el7-8                            /mysql57-community-release-el7-8.noarch                          8.2 k

Transaction Summary
============================================================================================================================================================================================
Install  1 Package

Total size: 8.2 k
Installed size: 8.2 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql57-community-release-el7-8.noarch                                                                                                                                   1/1 
  Verifying  : mysql57-community-release-el7-8.noarch                                                                                                                                   1/1 

Installed:
  mysql57-community-release.noarch 0:el7-8                                                                                                                                                  

Complete!
[root@54lxb ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64    MySQL Connectors Community               74
mysql-tools-community/x86_64         MySQL Tools Community                    74
mysql57-community/x86_64             MySQL 5.7 Community Server              307
[root@54lxb ~]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.24-1.el7 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.24-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.24-1.el7 will be installed
---> Package numactl-libs.x86_64 0:2.0.9-7.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.24-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.24-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================
 Package                                                 Arch                               Version                                     Repository                                     Size
============================================================================================================================================================================================
Installing:
 mysql-community-libs                                    x86_64                             5.7.24-1.el7                                mysql57-community                             2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-libs-compat                             x86_64                             5.7.24-1.el7                                mysql57-community                             2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.56-2.el7
 mysql-community-server                                  x86_64                             5.7.24-1.el7                                mysql57-community                             165 M
Installing for dependencies:
 mysql-community-client                                  x86_64                             5.7.24-1.el7                                mysql57-community                              24 M
 mysql-community-common                                  x86_64                             5.7.24-1.el7                                mysql57-community                             274 k
 numactl-libs                                            x86_64                             2.0.9-7.el7                                 os                                             29 k

Transaction Summary
============================================================================================================================================================================================
Install  3 Packages (+3 Dependent packages)

Total download size: 194 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.24-1.el7.x86_64.rpm is not installed
(1/6): mysql-community-common-5.7.24-1.el7.x86_64.rpm                                                                                                                | 274 kB  00:00:00     
(2/6): mysql-community-libs-5.7.24-1.el7.x86_64.rpm                                                                                                                  | 2.2 MB  00:00:00     
(3/6): mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm                                                                                                           | 2.0 MB  00:00:01     
(4/6): numactl-libs-2.0.9-7.el7.x86_64.rpm                                                                                                                           |  29 kB  00:00:00     
(5/6): mysql-community-client-5.7.24-1.el7.x86_64.rpm                                                                                                                |  24 MB  00:00:08     
(6/6): mysql-community-server-5.7.24-1.el7.x86_64.rpm                                                                                                                | 165 MB  00:00:39     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                       4.7 MB/s | 194 MB  00:00:41     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <[email protected]>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-8.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.24-1.el7.x86_64                                                                                                                               1/7 
  Installing : mysql-community-libs-5.7.24-1.el7.x86_64                                                                                                                                 2/7 
  Installing : mysql-community-client-5.7.24-1.el7.x86_64                                                                                                                               3/7 
  Installing : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                                          4/7 
  Installing : mysql-community-server-5.7.24-1.el7.x86_64                                                                                                                               5/7 
  Installing : mysql-community-libs-compat-5.7.24-1.el7.x86_64                                                                                                                          6/7 
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                                       7/7 
  Verifying  : numactl-libs-2.0.9-7.el7.x86_64                                                                                                                                          1/7 
  Verifying  : mysql-community-libs-compat-5.7.24-1.el7.x86_64                                                                                                                          2/7 
  Verifying  : mysql-community-libs-5.7.24-1.el7.x86_64                                                                                                                                 3/7 
  Verifying  : mysql-community-client-5.7.24-1.el7.x86_64                                                                                                                               4/7 
  Verifying  : mysql-community-server-5.7.24-1.el7.x86_64                                                                                                                               5/7 
  Verifying  : mysql-community-common-5.7.24-1.el7.x86_64                                                                                                                               6/7 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                                                                       7/7 

Installed:
  mysql-community-libs.x86_64 0:5.7.24-1.el7                 mysql-community-libs-compat.x86_64 0:5.7.24-1.el7                 mysql-community-server.x86_64 0:5.7.24-1.el7                

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.24-1.el7                      mysql-community-common.x86_64 0:5.7.24-1.el7                      numactl-libs.x86_64 0:2.0.9-7.el7                     

Replaced:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                                                                        

Complete!
[root@54lxb ~]# systemctl start mysqld
[root@54lxb ~]# systemctl enable mysqld
[root@54lxb ~]# systemctl daemon-reload
[root@54lxb ~]# grep 'temporary password' /var/log/mysqld.log
2018-11-21T02:54:50.327325Z 1 [Note] A temporary password is generated for root@localhost: sdr!BPjcq0w2
[root@54lxb ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24

Copyright (c) 2000, 2018, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%password%';
+---------------------------------------+--------+
| Variable_name                         | Value  |
+---------------------------------------+--------+
| default_password_lifetime             | 0      |
| disconnect_on_expired_password        | ON     |
| log_builtin_as_identified_by_password | OFF    |
| mysql_native_password_proxy_users     | OFF    |
| old_passwords                         | 0      |
| report_password                       |        |
| sha256_password_proxy_users           | OFF    |
| validate_password_check_user_name     | OFF    |
| validate_password_dictionary_file     |        |
| validate_password_length              | 8      |
| validate_password_mixed_case_count    | 1      |
| validate_password_number_count        | 1      |
| validate_password_policy              | MEDIUM |
| validate_password_special_char_count  | 1      |
+---------------------------------------+--------+
14 rows in set (0.00 sec)

mysql> exit
Bye
[root@54lxb ~]# 

其他MySQL常用命令:

1.导出

用 mysqldump 备份数据库,操作命令如下:

mysqldump -u 用户 -p 数据库名 > (目录)导出文件名

操作示例:

shell> mysqldump -u root -p dbname > /root/test.sql

如果只需要建表指令,则命令如下:

mysqldump -u 用户 -p -d 数据库名 > (目录)导出文件名

操作示例:

shell> mysqldump -u root -p -d dbname > /root/test.sql

如果只需要插入数据的sql命令,而不需要建表命令,则命令如下:

mysqldump -u 用户 -p -t 数据库名 > (目录)导出文件名

操作示例:

shell> mysqldump -u root -p -t dbname > test.sql

备份单个数据表:

mysqldump -uroot -p123 dbname tablename >  /root/testtb.sql

备份多个数据表:

mysqldump -u root -p wordpress wp_posts wp_options > wordpress_1.sql

远程备份数据:

mysqldump -h ip -uroot -p123 database > c:\nowamagic.sql

2.导入

mysql>source /root/test.sql 

猜你喜欢

转载自blog.csdn.net/u013902368/article/details/85258048
今日推荐