当前位置: 首页 > Mysql > 正文

mysql安装-linux6.5通过rpm包方式安装mysql5.6.21

今天开始学习mysql数据库,和其他软件一样,先安装mysql数据库,linux操作系统安装mysql数据库大致有两种方法,一种是通过rpm包方式安装,一种是源码包安装,当然还有一种方法,就是将其他服务器上安装好的mysql数据库直接拷贝过来使用,本人不推荐也不提倡这种方式,以后也不会提及。

本文主要演示如何在linux系统上通过rpm包的方式来安装mysql数据库,这也是相对简单的安装方法,Linux版通常有以下几个安装文件。

[root@mysql-1 mysql]# ll
total 146044
-rw-r--r-- 1 root root 33278710 Aug  3 11:46 mysql-5.6.26.tar.gz
-rw-r--r-- 1 root root 23156366 May 16  2015 MySQL-client-5.6.21-1.rhel5.x86_64.rpm
-rw-r--r-- 1 root root  4579502 May 16  2015 MySQL-devel-5.6.21-1.rhel5.x86_64.rpm
-rw-r--r-- 1 root root 88524802 May 16  2015 MySQL-server-5.6.21-1.rhel5.x86_64.rpm

mysql-5.6.26.tar.gz为源码包安装文件,本文不做演示。MySQL-server-5.6.21-1.rhel5.x86_64.rpm为服务端程序安装文件,如果要搭建mysql数据库,必须安装。MySQL-client-5.6.21-1.rhel5.x86_64.rpm为客户端程序安装包,如果不安装,将没有mysql命令。MySQL-devel-5.6.21-1.rhel5.x86_64.rpm为开发工具相关的安装包,如果不是作为开发环境,可以不安装。

本案例使用的操作系统为OEL6.5,mysql安装文件为5.6.21 for rhel,由于OEL基本就是红帽linux的克隆版,相当于海尔兄弟,只是衣服不一样而已,所以,红帽版的安装文件,在OEL上也可以安装。下面将记录本次安装的详细过程,包括遇到的问题及解决方法。

和其他rpm安装包一样,可以使用rpm –ivh命令来安装mysql的rpm包,当然也可以使用yum来安装,本案例使用rpm命令安装。

[root@mysql-1 mysql]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
error: Failed dependencies:
        MySQL-server conflicts with mysql-server-5.1.71-1.el6.x86_64

这是由于在安装OEL操作系统的时候,即使不选mysql选项,默认基本也会把mysql数据库给安装上,上面的错误就是因为在安装操作系统的时候已经安装了mysql5.1.71版本,rpm安装的方式只能存在一个mysql软件,所以在安装5.6.21版本之前,需要先卸载5.1.71版本,通过rpm –e命令可以卸载安装过的rpm包。

[root@mysql-1 mysql]# rpm -e mysql-server
error: Failed dependencies:
        mysql-server is needed by (installed) akonadi-1.2.1-2.el6.x86_64

在卸载mysql5.1.71版本时,遇到了依赖关系问题,使用—nodeps方式跳过依赖关系检查,即可卸载。

[root@mysql-1 mysql]# rpm -e mysql-server --nodeps

卸载后再次安装。

[root@mysql-1 mysql]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
        file /usr/share/mysql/charsets/README from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/dutch/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/english/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/estonian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/french/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/german/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/greek/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/hungarian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/italian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/japanese/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/korean/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/norwegian-ny/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/norwegian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/polish/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/portuguese/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/romanian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/russian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/serbian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/slovak/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/spanish/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/swedish/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/ukrainian/errmsg.sys from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/ascii.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/cp1250.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/cp1251.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/cp1256.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/cp1257.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/cp850.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/cp852.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/cp866.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/dec8.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/geostd8.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/greek.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/hebrew.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/hp8.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/keybcs2.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/koi8r.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/koi8u.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/latin1.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/latin2.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/latin5.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/latin7.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/macce.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/macroman.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/share/mysql/charsets/swe7.xml from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64
        file /usr/bin/my_print_defaults from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-5.1.71-1.el6.x86_64
        file /usr/share/man/man1/my_print_defaults.1.gz from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-5.1.71-1.el6.x86_64

再次安装时,又遇到上面的错误,虽然日志信息比较多,仔细看会发现,上面的一堆错误都是因为mysql-libs这个包已存在引起的,通过rpm –e命令卸载这个包。

[root@mysql-1 mysql]# rpm -e mysql-libs --nodeps

再次安装。

[root@mysql-1 mysql]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
        file /usr/bin/my_print_defaults from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-5.1.71-1.el6.x86_64
        file /usr/share/man/man1/my_print_defaults.1.gz from install of MySQL-server-5.6.21-1.rhel5.x86_64 conflicts with file from package mysql-5.1.71-1.el6.x86_64

这是因为mysql这个包又冲突了,继续用rpm –e命令干掉。

[root@mysql-1 mysql]# rpm -e mysql --nodeps

再次安装基本就不会存在其他问题了,基本冲入的就是mysql-server、mysql-libs、mysql这三个包。

[root@mysql-1 mysql]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
2016-01-28 11:16:22 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-28 11:16:22 12351 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-28 11:16:22 12351 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-28 11:16:22 12351 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-28 11:16:22 12351 [Note] InnoDB: Memory barrier is not used
2016-01-28 11:16:22 12351 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-28 11:16:22 12351 [Note] InnoDB: Using Linux native AIO
2016-01-28 11:16:22 12351 [Note] InnoDB: Using CPU crc32 instructions
2016-01-28 11:16:22 12351 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-28 11:16:22 12351 [Note] InnoDB: Completed initialization of buffer pool
2016-01-28 11:16:22 12351 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-01-28 11:16:22 12351 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-01-28 11:16:22 12351 [Note] InnoDB: Database physically writes the file full: wait...
2016-01-28 11:16:22 12351 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-01-28 11:16:24 12351 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-01-28 11:16:24 12351 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-01-28 11:16:24 12351 [Warning] InnoDB: New log files created, LSN=45781
2016-01-28 11:16:24 12351 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-01-28 11:16:24 12351 [Note] InnoDB: Doublewrite buffer created
2016-01-28 11:16:24 12351 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-28 11:16:24 12351 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-01-28 11:16:24 12351 [Note] InnoDB: Foreign key constraint system tables created
2016-01-28 11:16:24 12351 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-01-28 11:16:24 12351 [Note] InnoDB: Tablespace and datafile system tables created.
2016-01-28 11:16:24 12351 [Note] InnoDB: Waiting for purge to start
2016-01-28 11:16:24 12351 [Note] InnoDB: 5.6.21 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2016-01-28 11:16:24 12351 [Note] Binlog end
2016-01-28 11:16:24 12351 [Note] InnoDB: FTS optimize thread exiting.
2016-01-28 11:16:24 12351 [Note] InnoDB: Starting shutdown...
2016-01-28 11:16:26 12351 [Note] InnoDB: Shutdown completed; log sequence number 1625977

2016-01-28 11:16:26 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-28 11:16:26 12373 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-28 11:16:26 12373 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-28 11:16:26 12373 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-28 11:16:26 12373 [Note] InnoDB: Memory barrier is not used
2016-01-28 11:16:26 12373 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-28 11:16:26 12373 [Note] InnoDB: Using Linux native AIO
2016-01-28 11:16:26 12373 [Note] InnoDB: Using CPU crc32 instructions
2016-01-28 11:16:26 12373 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-28 11:16:26 12373 [Note] InnoDB: Completed initialization of buffer pool
2016-01-28 11:16:26 12373 [Note] InnoDB: Highest supported file format is Barracuda.
2016-01-28 11:16:26 12373 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-28 11:16:26 12373 [Note] InnoDB: Waiting for purge to start
2016-01-28 11:16:26 12373 [Note] InnoDB: 5.6.21 started; log sequence number 1625977
2016-01-28 11:16:26 12373 [Note] Binlog end
2016-01-28 11:16:26 12373 [Note] InnoDB: FTS optimize thread exiting.
2016-01-28 11:16:26 12373 [Note] InnoDB: Starting shutdown...
2016-01-28 11:16:28 12373 [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

安装完成,通过安装日志,可以看到mysql给的一些很重要的提示,首先是密码相关的介绍。

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

这段日志信息告诉安装者,root用户的密码存放在/root/.mysql_secret文件中,使用root用户登录mysql数据库需要使用密码,需要从这个文件中获取。

[root@mysql-1 mysql]# cat /root/.mysql_secret 
# The random password set for the root user at Thu Jan 28 11:16:24 2016 (local time): ocvYqBfQEBUYpZ2N

加密的密码可以在用户登录时直接使用,但是在登录mysql数据库之前,还需要安装mysql的客户端才可以。

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.

这段日志告诉安装者,第一次登录数据库必须要修改密码,修改密码可以使用SET PASSWORD命令,修改密码下文会介绍。

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.

这段日志告诉安装者,可以通过/usr/bin/mysql_secure_installation脚本来删除test数据库和匿名用户,主要是匿名用户允许任何人登录mysql数据库,而test数据库存在安全漏洞,生产环境建议在正式使用前,删除test数据库和匿名用户。删除数据库的方法有很多种,比如在操作系统上直接删除对应的文件夹,或者在数据库中通过drop database命令删除响应的数据库都行。下面运行下这个脚本,看看这个脚本都能做哪些事情。

[root@mysql-1 test]# /usr/bin/mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 

此处需要输入mysql数据库的root用户的密码,输入前文提到的密码文件中记录的密码即可。

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n

此处会提示是否修改mysql数据库的root用户的密码,输入Y修改,输入N为不修改。

... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n

此处提示是否删除匿名用户,输入Y确认删除,输入Y为不删除。

... skipping.

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n

此处提示是否禁止mysql数据库的root用户使用本地验证的方式登录数据库,也就是不使用密码直接登录数据库,输入Y为禁止,输入N为不禁止。

... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n

此处提示是否删除test数据库,输入Y删除,输入N为不删除。

... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] n

此处提示是否更新mysql数据库的权限表,确认以上设置是否生效,输入Y为确认以上设置,输入N为不设置。

... skipping.

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...

脚本运行完成,仔细读上面的提示信息,会发现mysql通过日志告诉我们一些很多基础知识,多初学者很重要,比如匿名用户可以不使用用户名和密码登录数据库、root用户可以在本地不使用密码登录数据库、test数据库所有数据库的用户都有权限使用等,初学者可能都不知道这些,如果在生产环境不对以上方面做处理,很可能给数据库带来安全隐患,而mysql_secure_installation脚本就可以很方便的解决这些安全方面的问题。下面继续看mysql的安装日志。

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

这段日志告诉安装者一些常用的mysql网站。

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

这段日志也就是安装日志的最后部分,告诉安装者mysql配置文件的位置,使用rpm包安装mysql,配置文件默认在/usr路径下,名字为my.cnf,为文本文件可以直接编辑修改。使用rpm包安装mysql,mysql的配置基本上使用的都是默认参数,我打开my.cnf文件,发现里面只有一行是非注释的,其他都是注释掉的参数。

下面进行登录数据库演示,在登录mysql数据库前,需要先安装mysql的客户端。

 [root@mysql-1 mysql]# rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]

顺便把开发工具包也顺手装上,本次安装数据库并不是为开发环境使用,纯属练手,既然是学习,就都安装上吧。

[root@mysql-1 mysql]# rpm -e mysql-devel
[root@mysql-1 mysql]# rpm -ivh MySQL-devel-5.6.21-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-devel            ########################################### [100%]

安装完mysql后,mysql服务并没有启动,需要启动下mysql,顺便可以检查下安装是否存在问题,如果mysql服务无法启动,那肯定就是安装存在问题了。

[root@mysql-1 mysql]# /etc/init.d/mysql start
Starting MySQL.[  OK  ]
[root@mysql-1 mysql]# /etc/init.d/mysql stop
Shutting down MySQL..[  OK  ]

启动后,看看mysql都启动了哪些进程。

[root@mysql-1 mysql]# ps -ef | grep mysql
root     12586     1  0 11:20 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/mysql-1.pid
mysql    12687 12586  0 11:20 pts/0    00:00:04 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/mysql-1.err --pid-file=/var/lib/mysql/mysql-1.pid

可见,启动mysql会启动上面的两个进程,从这两个进程可以看出挺多东西,比如mysql的文件分布。从上面的进程信息可以看到,mysql的客户端命令基本存在/usr/bin目录下,mysql数据库的数据文件存放在datadir目录下,也就是/var/lib/mysql目录下,mysql的服务端命令基本存放在/usr/sbin目录下。

以下是datadir目录也就是/var/lib/mysql目录下的数据信息。

[root@mysql-1 mysql]# cd /var/lib/mysql
[root@mysql-1 mysql]# ll
total 110628
-rw-rw---- 1 mysql mysql       56 Jan 28 11:19 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 Jan 28 11:20 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Jan 28 11:20 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Jan 28 11:16 ib_logfile1
drwx--x--x 2 mysql mysql     4096 Jan 28 11:16 mysql
-rw-r----- 1 mysql root      7646 Jan 28 11:20 mysql-1.err
-rw-rw---- 1 mysql mysql        6 Jan 28 11:20 mysql-1.pid
srwxrwxrwx 1 mysql mysql        0 Jan 28 11:20 mysql.sock
drwx------ 2 mysql mysql     4096 Jan 28 11:16 performance_schema
-rw-r--r-- 1 root  root       113 Jan 28 11:16 RPM_UPGRADE_HISTORY
-rw-r--r-- 1 mysql mysql      113 Jan 28 11:16 RPM_UPGRADE_MARKER-LAST
drwxr-xr-x 2 mysql mysql     4096 Jan 28 11:16 test

这个目录下面的文件夹就是一个数据库,比如删除掉test目录,就相当于删除了test数据库,创建一个文件夹就相当于创建了一个数据库,在mysql数据库中,create database命令其实就是在这个目录下面创建目录。这个datadir参数指定的目录下面的所有东西就相当于一个mysql实例。

下面登录mysql数据库。

[root@mysql-1 mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.21

Copyright (c) 2000, 2014, 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> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql>

提示必须要重新设置root的密码。

mysql> set password for root@'localhost'=password('dbdream');
Query OK, 0 rows affected (0.00 sec)

修改密码后,就可以用了。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

可以看到,mysql、performance_schema、test这三个数据库,在datadir参数对于的目录下面,也就是/var/lib/mysql目录下面都有一个名字一样的目录,而information_schema并没有对应的目录,这是因为information_schema是基于内存的一个特殊的数据库。

改完密码了,是不是在安装mysql的时候创建的那个密码文件也会随之更改呢?答案是否定的,再次查看密码文件,会发现根本没有变化。

[root@mysql-1 mysql]# cat /root/.mysql_secret 
# The random password set for the root user at Thu Jan 28 11:16:24 2016 (local time): ocvYqBfQEBUYpZ2N

这是因为,mysql的密码是存在数据库中的,并不是存在操作系统上,这个文件只是告诉安装者mysql数据库的root密码的初始密码是什么而已,下面查看下数据库中的用户密码信息。

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed


mysql> select Host,User,Password from user;
+-----------+------+-------------------------------------------+
| Host      | User | Password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *6A7A490FB9DC8C33C2B025A91737077A7E9CC5E5 |
| mysql-1   | root | *E128C3C2FCA72DC0A9B9D87F2034A63A9B436F65 |
| 127.0.0.1 | root | *E128C3C2FCA72DC0A9B9D87F2034A63A9B436F65 |
| ::1       | root | *E128C3C2FCA72DC0A9B9D87F2034A63A9B436F65 |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)

从以上信息可以看出来,mysql数据库的密码粒度很细,可以到IP级别,也就是同一个用户对于不同的IP可以有不同的密码,以上这4条记录,其实都是同一台服务器,但是连接时使用的方式不同,使用的密码也不相同,以后会对密码做专门实验,这里就不做介绍了。

本文固定链接: http://www.dbdream.com.cn/2016/03/mysql%e5%ae%89%e8%a3%85-linux6-5%e9%80%9a%e8%bf%87rpm%e5%8c%85%e6%96%b9%e5%bc%8f%e5%ae%89%e8%a3%85mysql5-6-21/ | 信春哥,系统稳,闭眼上线不回滚!

该日志由 dbdream 于2016年03月16日发表在 Mysql 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: mysql安装-linux6.5通过rpm包方式安装mysql5.6.21 | 信春哥,系统稳,闭眼上线不回滚!
关键字: , ,

mysql安装-linux6.5通过rpm包方式安装mysql5.6.21:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter