1.检测系统是否已经安装过mysql或其依赖
若已装过要先将其删除,否则第4步使用yum安装时会报错
#yum list installed | grep mysql
mysql-libs.i686 5.1.71-1.el6 @anaconda-CentOS-201311271240.i386/6.5
#yum -y remove mysql-libs.i686
2.从mysql的官网下载mysql57-community-release-el6-5.noarch.rpm
(注意这里的el6-5即适配RHEL6.5的版本,如果下载了其它版本后面的安装过程中可能会报错):
#wget --no-check-certificate dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
3.安装第一步下载的rpm文件:
# yum install mysql-community-release-el6-5.noarch.rpm
安装成功后,我们可以看到/etc/yum.repos.d/目录下增加了以下两个文件
1 # ls /etc/yum.repos.d/
2 mysql-community-source.repo
3 mysql-community.repo
4.查看mysql57的安装源是否可用,如不可用请自行修改配置文件
# vim /etc/yum.repos.d/mysql-community.repo
使mysql57下面的enable=1
若有mysql其它版本的安装源可用,也请自行修改配置文件使其enable=0
5.执行下面的操作显示如下,则证明配置正确。
# yum repolist enabled | grep mysql
mysql-connectors-community MySQL Connectors Community 13
mysql-tools-community MySQL Tools Community 18
mysql57-community-dmr MySQL 5.7 Community Server Development Milesto 65
6.使用yum安装mysql:
#yum install mysql-community-server
7.启动mysql服务:
#service mysqld start
8.修改root密码:
使用无需验证的方式,修改my.cnf,在/etc/my.cnf 中 增加skip-grant-tables=1
保存my.cnf,重启mysql
[root@cdh etc]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@cdh etc]#
登录上mysql,然后切换到mysql数据库
[root@cdh etc]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.3-m13 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
接下来就是重点了修改密码,需要修改两次,一次authentication_string,一次 password
mysql> UPDATE user SET authentication_string=PASSWORD("root") WHERE user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0 mysql>
update user set password=password('root') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
然后把之前的配置skip-grant-tables=1去掉,重新启动mysql
[root@cdh etc]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@cdh etc]# mysql -uroot -p
mysql: [Warning] Using a password on the command line interface can be insecure.
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.3-m13
Copyright (c) 2000, 2013, 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.
mysql>
设置密码验证只是验证长度 mysql>set global validate_password_policy=0;
设置密码最小长度为1 mysql>set global validate_password_length=1;
最后还是要再执行下修改密码的语句的
mysql> use mysql
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> SET PASSWORD = PASSWORD('root');
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql>
9.将mysql加到系统服务中并设置开机启动
加入到系统服务:chkconfig --add mysqld
自动启动:chkconfig mysqld on
10.开启mysql的远程登录
默认情况下mysql为安全起见,不支持远程登录mysql,所以需要设置开启 远程登录mysql的权限
登录mysql后输入如下命令:
grant all privileges on *.* to 'root' @'%' identified by 'root';
flush privileges;
11.开放Linux的对外访问的端口3306
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save ---将修改永久保存到防火墙中