@CentOS安装MySQL

这里通过yum来进行MySQL数据库的安装,通过这种方式进行安装,可以将跟MySQL相关的一些服务、jar包都给我们安装好,所以省去了很多不必要的麻烦!!!

1.卸载掉原有MySQL

目前主流Linux系统版本基本上都集成了MySQL数据库,我们可以通过如下命令来查看我们的操作系统上是否已经安装了MySQL数据库

有的话,我们就通过rpm -e命令或者rpm ---nodeps命令来卸载掉,在删除完以后我们可以通过rpm -qa | grep mysql命令来查看MySQL是否已经卸载成功!!

至此,系统原有的MySQL删除完毕。

2.在MySQL官网下载安装MySQL-5.6.21所需的rpm软件包。

需要下载三个rpm软件包
MySQL-client-5.6.21-1.rhel5.x86_64.rpm  
MySQL-devel-5.6.21-1.rhel5.x86_64.rpm  
MySQL-server-5.6.21-1.rhel5.x86_64.rpm 

[root@localhost software]# wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-server-5.6.21-1.rhel5.x86_64.rpm
[root@localhost software]# wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-devel-5.6.21-1.rhel5.x86_64.rpm 
[root@localhost software]# wget http://dev.mysql.com/Downloads/MySQL-5.6/MySQL-client-5.6.21-1.rhel5.x86_64.rpm

3.下载完之后,安装三个rpm软件包

[root@localhost software]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 

error: Failed dependencies:
        libaio.so.1()(64bit) is needed by MySQL-server-5.6.21-1.rhel5.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.21-1.rhel5.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.21-1.rhel5.x86_64
安装MySQL-server报错,原因是没有安装libaio,系统缺少libaio.so此软件包,下边yum安装一下libaio.so软件包。

[root@localhost software]#yum install -y libaio 
[root@localhost software]# rpm -ivh MySQL-server-5.6.21-1.rhel5.x86_64.rpm 

[root@localhost software]# rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm  

[root@localhost software]# rpm -ivh MMySQL-devel-5.6.21-1.rhel5.x86_64.rpm  

注意,在安装server的时候一定要仔细看一下安装的详细信息,因为默认的初始密码会包含在其中,有的版本默认是没有密码的,我安装的这个则是有密码的~

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是不是安装成功了呢?

可以通过查看mysql安装时创建的mysql用户和mysql组

或者可以执行mysqladmin --version,打印出消息即成功~

4.mysql服务的启动与停止

 

5.修改密码

使用默认的初始密码(/root/.mysql_secret)登录之后必须修改密码才能执行后续操作

6.mysql的安装位置

即mysql数据库的数据库~

拿windows上安装的数据库为例,我们把mysql安装在D盘上了,那我们创建的数据库位置在哪呢?

所以上面的--datadir=/var/lib/mysql就存放我们创建的数据库文件的存放路径

标红的是mysql自带的数据库~

 mysql默认的配置文件目录

mysql相关命令在/usr/bin目录下

mysql启动停止的相关脚本在/etc/init.d/mysql下

8.修改配置文件位置。

9.修改MySQL默认字符集

所以存中文会出现乱码~

修改mysql.cnf文件即可

其实一般建数据库和数据库表的时候都会指定编码方式,所以不改这里的编码也没什么关系,但是建库和建表指定编码方式是一种好的实践,一定要这样做~

原文地址:https://www.cnblogs.com/winner-0715/p/4994759.html