首页 » 数据库 » Mysql » 安装MYSQL5.6,yum安装mysql

安装MYSQL5.6,yum安装mysql

 
文章目录

在CentOS7下,默认安装的数据库为MariaDB,属于MySQL数据库的一个分支,如果需要安装mysql的5.6版本,需要进行yum的相应配置,具体安装方法如下:

1、下载 MySQL Yum Repository

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

2、添加 MySQL Yum Repository

rpm -ivh mysql-community-release-el7-5.noarch.rpm

3、验证下是否添加成功

执行yum repolist enabled | grep "mysql.-community."

[root@vpc-db ~]# yum repolist enabled | grep "mysql.-community." 

mysql-connectors-community/x86_64 MySQL Connectors Community 105
mysql-tools-community/x86_64 MySQL Tools Community 89 
mysql56-community/x86_64 MySQL 5.6 Community Server 463

4、选择要启用 MySQL 版本

查看 MySQL 版本,执行yum repolist all | grep mysql

可以看到 5.5, 5.7 版本是默认禁用的,因为现在最新的稳定版是 5.6

可以通过类似下面的语句来启动某些版本

yum-config-manager --disable mysql56-community yum-config-manager --enable mysql57-community-dmr

或者通过修改 /etc/yum.repos.d/mysql-community.repo 文件

#Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

其中 enabled=0 是指禁用,enabled=1 指启用。 注意: 任何时候,只能启用一个版本。

5、通过 Yum 来安装 MySQL

yum install mysql-community-server

6、MySQL 安全设置(设置密码)

设置root的管理密码,禁止root账号的远程连接

[root@vpc-db lib]# 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 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 ... 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

  • 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...

7、远程访问设置

创建一个普通用户 sa ,密码是 some_pass

CREATE USER 'sa'@'%' IDENTIFIED BY 'some_pass';

给这个用户授予 SELECT,INSERT,UPDATE,DELETE 的远程访问的权限,这个账号一般用于提供给实施的系统访问

GRANT SELECT,INSERT,UPDATE,DELETE ON . TO 'sa'@'%';

创建一个管理员用户 admin 账号 ,密码是 some_pass

CREATE USER 'admin'@'%' IDENTIFIED BY 'some_pass';

给这个用户授予所有的远程访问的权限。这个用户主要用于管理整个数据库、备份、还原等操作。

GRANT ALL ON . TO 'admin'@'%';

使授权立刻生效

flush privileges;

8、设置字符集

一般的,为了支持中文,我们应该讲字符集设为 UTF-8, 执行下面命令查看当前 MySQL 字符集 SHOW VARIABLES LIKE 'character%';

修改 /etc/my.cnf 文件,添加字符集的设置

[mysqld] character_set_server = utf8

[mysql] default-character-set = utf8

重启 MySQL ,可以看到字符集已经修改了

9、创建数据库

Create DATABASE IF NOT EXISTS testdb default charset utf8 COLLATE utf8_general_ci;

9、备份、还原

备份

mysqldump --socket=/home/data/mysql/mysql.sock --single-transaction=TRUE -u root -p emsc > emsc.sql

还原

mysql --socket=/home/data/mysql/mysql.sock -u root -p emsc < emsc.sql

原文链接:安装MYSQL5.6,yum安装mysql,转载请注明来源!

0