linux下yum安装配置mysql数据库

环境:centos 6.5 + mysql 5.6.26


要使用yum 安装mysql,要使用mysql的yum仓库,先从官网下载适合你系统的仓库

​ http://dev.mysql.com/downloads/repo/yum/ ​​ centos 6.5 对应的是mysql-community-release-el6-5.noarch.rpm


(进入http://dev.mysql.com/downloads/repo/,下载RedHat Enterprise Linux 6 / Oracle Linux 6版。)


然后安装一下这个仓库列表


sudo yum localinstall mysql-community-release-el6-5.noarch.rpm 


执行这个命令后就能看到可安装的mysql


yum repolist enabled | grep "mysql.*-community.*"


如果我们是要安装最新的版本,那么可以直接执行


sudo yum install mysql-community-server


如果我们要选择版本,可以先执行下面这个命令查看一下有哪些版本


yum repolist all | grep mysql


如果要选择版本的话,有两种方式,一种是使用命令来


shell> sudo yum-config-manager --disable mysql56-community


shell> sudo yum-config-manager --enable mysql57-community-dmr


这个命令就是在仓库中启用5.7版本的,禁用5.6版本子仓库


或者编辑/etc/yum.repos.d/mysql-community.repo文件


# Enable to use MySQL 5.6


[mysql56-community]


name=MySQL 5.6 Community Server


baseurl=//repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/


enabled=1


gpgcheck=1


gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 


enabled=0表示禁用


比如要安装5.7版本的mysql,要确定5.6的enabled=0,5.7的enabled=1,一次保证只启用一个子仓库


# Note: MySQL 5.7 is currently in development. For use at your own risk.


# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/


[mysql57-community-dmr]


name=MySQL 5.7 Community Server Development Milestone Release


baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/


enabled=1


gpgcheck=1


gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql




然后我们又可以愉快的安装mysql了


sudo yum install mysql-community-server


安装完成后我们启动mysql


sudo service mysqld start



查看mysql状态


sudo service mysqld status



可能出现的问题


1 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.


解决: 在my.cnf mysqld 下添加 explicit_defaults_for_timestamp=true



2 启动服务是报错 ***


检查发现mysql的目录下有如下文件:


[root@tserver mysql]# ls


ibdata1  ib_logfile0  ib_logfile1  mysql  RPM_UPGRADE_HISTORY  RPM_UPGRADE_MARKER-LAST  test  tserver.err



删除了如下三个文件:



[root@tserver mysql]# rm ibdata1  ib_logfile0  ib_logfile1 


rm: remove regular file `ibdata1'? yes      


rm: remove regular file `ib_logfile0'? yes


rm: remove regular file `ib_logfile1'? yes



重新启动mysql server就可以了:



3 如果远程连接这个mysql会出现 **** is not allowed to connect to this mysql 


mysql -uroot -p


输入root的密码,默认是没有密码的


登录后也可以修改这个密码




>mysql use mysql


>mysql set password for 'root' = password('123456');


或者


>mysql set password for 'root'@'localhost' = password('123456');


给要远程连接的用户赋权限


>mysql GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;


让权限生效


>mysql flush privileges;




这是给另外一个用户赋权限的命令


>mysql GRANT USAGE ON *.* TO 'mysqladmin'@'%' IDENTIFIED BY 'mysqladmin123456' WITH GRANT OPTION;



下面是创建其它用户用的命令,但都没成功


CREATE USER mysqladmin IDENTIFIED BY 'mysqladmin123456';


insert into mysql.user(Host,User,Password) values("%","mysqladmin",password("mysqladmin123456"));


insert into mysql.user(Host,User,Password) values('%','mysqladmin',password('mysqladmin123456'));


ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value