一、安装MySQL

首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安装mysql的步骤。

 

#列出所有被安装的rpm package
rpm -qa | grep mariadb

 

#卸载

rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64

错误:依赖检测失败:
        libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要
        libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要

 

#强制卸载,因为没有–nodeps

rpm -e –nodeps mariadb-libs-5.5.37-1.el7_0.x86_64

http://mirrors.sohu.com/mysql/MySQL-5.5/ 上下载server,devel,client对应的包

MySQL-server-5.5.44-1.el6.i686.rpm
MySQL-devel-5.5.44-1.el6.i686.rpm
MySQL-client-5.5.44-1.el6.i686.rpm

使用ftp上传到服务器,cd到文件目录

执行rpm -ivh MySQL-server-5.5.44-1.el6.i686.rpm MySQL-devel-5.5.44-1.el6.i686.rpm MySQL-client-5.5.44-1.el6.i686.rpm

如果缺少so的包,比如libaio.so.1()(64bit) is needed by MySQL-server-5.5.44-1.el6.i686.rpm

只需要yum install libaio.so.1,如果安装完还缺的话,同样执行yum安装需要依赖的包即可。

安装完成后service mysql start启动mysql服务,

然后再输入mysql,若出现以下提示信息,说明成功。

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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.

二、修改密码。
格式:mysqladmin -u用户名 -p旧密码 password 新密码

1、给root加个密码123456。键入以下命令:
# mysqladmin -u root -password 123456

2、再将root的密码改为56789。
# mysqladmin -u root -p123456 password 56789

首次安装时,默认密码为空,可以使用如下命令修改root密码,

mysqladmin -u root  password mypassword

mypassword 为你设定的新密码

然后再次登录

mysql -u root –p

 

rpm包安装的MySQL是不会安装/etc/my.cnf文件的,解决方法,只需要复制/usr/share/mysql目录下的my-huge.cnf 文件到/etc目录,并改名为my.cnf即可

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

到此MySQL安装就完了。