按:下面文章经过我一路测试没有问题,是篇好文,在此感谢作者 。另因原文有些啰嗦,我自己有所删改,并尾后增加了一大段。
出处:https://www.cnblogs.com/renjidong/p/7047396.html
1.先检测系统是否自带安装mysql
# yum list installed | grep mysql
2.如果发现有系统自带mysql,删除之
# yum -y remove mysql-libs.x86_64
3.从网络获取mysql5.6(79M),解释一下,这个rpm还不是mysql的安装文件,只是两个yum源文件# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
4.接着执行这句,执行后在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo# rpm -ivh mysql-community-release-el6-5.noarch.rpm
5.这个时候,可以用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件#yum repolist all | grep mysql
6.安装mysql 服务器命令(一路yes):# yum install mysql-community-server
7.安装成功后,启动mysql# service mysqld start
8.由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码# mysql -u root
mysql> use mysql;mysql> update user set password=PASSWORD('123456') where User='root';mysql> flush privileges; 9.查看mysql是否自启动,并且设置开启自启动命令# chkconfig --list | grep mysqld
# chkconfig mysqld on 10.mysql安全设置(系统会一路问你几个问题,基本上一路yes):# mysql_secure_installation
以下为我个人添加的内容:
进入mysql数据库管理控制台,让远程可以访问。
#mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.0.67 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> grant all privileges on *.* to root@'%' identified by "root";Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> quitBye上面的步骤是进行授权
然后重启mysqld服务
# service mysqld restartStopping MySQL: [ OK ]Starting MySQL: [ OK ]再次进入mysql管理控制台(修改密码这一步不可或缺,否则容易出现“access denied for user root @localhost”错误)
# mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.0.67 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set password=password('12345678') where user='root';Query OK, 5 rows affected (0.00 sec)Rows matched: 5 Changed: 5 Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> quitBye以上步骤是修改root用户的密码
之后开启防火墙的3306端口
# vi /etc/sysconfig/iptables以下是/etc/sysconfig/iptables的内容,其中蓝色一行是新加的。这一行可以由上一行复制得到,方法是在22哪行按下yy进行行复制,然后按p进行粘贴,然后点insert键进入编辑模式,修改22为3306,然后点esc,输入wq保存退出。# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT防火墙重启
# service iptables restartiptables: Flushing firewall rules: [ OK ]iptables: Setting chains to policy ACCEPT: filter [ OK ]iptables: Unloading modules: [ OK ]iptables: Applying firewall rules: [ OK ]之后就可以在终端上敲#ifconfig,找出虚拟机对应的ip地址,比如说是192.168.0.100,然后就可以用mysql-front或程序连接数据库了。
2018年3月25日14点41分