您的位置:首页 > 运维架构 > Linux

阿里云Centos7安装Mysql方法

2016-03-21 23:31 483 查看
1 常规错误的yum安装方法:

在CentOS 6.5以及低版本的系统中通过yum方式快速地搭建了LNMP环境,但是在CentOS 7或CentOS 7.1等高版本系统中就不能用此方法安装。原理如下:





从上面的安装结果可以看出,没有安装mysql数据库,而是安装了mariadb数据!因为在CentOS 7和CentOS 7.1系统中,默认安装的mysql是它的分支mariadb。这里引用下百度百科关于mariadb的描述:
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。


因此,下面这些正常的MySQL操作都是无效的:



2 正确的安装方法:先查看可以安装哪些版本。

众所周知,Linux系统自带的repo是不会自动更新每个软件的最新版本(基本都是比较靠后的稳定版),所以无法通过yum方式安装MySQL的高级版本。所以我们需要先安装带有当前可用的mysql5系列社区版资源的rpm包。



这时查看当前可用的mysql安装资源:



从上面的列表可以看出, 
mysql56-community/x86_64
 和 
MySQL
5.6 Community Server
 可以使用。

因此,我们就可以直接用yum方式安装了MySQL5.6版本了。





3 MySQL安装完成后,进行相关配置

安装完MySQL后,需要进行一些基础配置工作:
接下来是重点的!!!!我先把内容贴出来。

#######安装成功后,将其加入开机启动

[root@typecodes ~]# systemctl enable mysqld

#######启动mysql服务进程

[root@typecodes ~]# systemctl start mysqld

#######配置mysql(设置密码等)

[root@typecodes ~]# 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): 

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] y                  [设置root用户密码]

New password: 

Re-enter new password: 

Password updated successfully!

Reloading privilege tables..

 ... Success!

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] y                 [删除匿名用户]

 ... Success!

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] y       [禁止root远程登录]

 ... Success!

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] y          [删除test数据库]

 - Dropping test database...

ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist

 ... Failed!  Not critical, keep moving...

 - Removing privileges on test database...

 ... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y            [刷新权限]

 ... Success!

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

Cleaning up...









接下来的操作和正常的一样了,登录如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: