正确的安装方法:
1. yum install mysql-server
2. yum install mysql
3.
mysqladmin -u root password '123456'
4. mysql -u root -p123456
5. 在数据库中执行这两条命令
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
flush privileges;
6. 退出数据库
7. 修改防火墙配置
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
8. 数据库自启动
chkconfig --list mysqld
chkconfig mysqld on
下面
newpassword位置,就是我们要输入的密码
# /etc/init.d/mysqld stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
select host, user from user;
+-----------+------+
| host
| user |
+-----------+------+
| %
| root |
| 127.0.0.1 | root |
| fn1
|
|
| fn1
| root |
| localhost | root |
+-----------+------+
mysql>
update user set password=password('123456') where user='root';
mysql>
flush privileges;
mysql> quit
mysql>
mysql> quit
ps,然后kill掉后台启动的
mysqld_safe
# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
mysql>
一般mysql服务器上的防火墙开着,会影响到其他机器连向他的mysql数据库
vim /etc/sysconfig/iptables, 下面红色那行是增加的允许3306被访问,一定要增加在
icmp-host-prohibited的两行配置之前:
# 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-prohibited
COMMIT
======================================
1. 确保mysql安装正确
service mysqld status
一般需要安装 mysql-server, mysql, mysql-devel
2. 重启mysql服务
默认安装的mysql如果无法重启,则可以删除mysql.sock,再重新启动下就可以了
This will stop the running services before powering down the machine.
Based on Centos, an additional method for getting it back up again when you run into this problem is to move mysql.sock:
# mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak
# service mysqld start
Restarting the service creates a new entry called mqsql.sock
Based on Centos, an additional method for getting it back up again when you run into this problem is to move mysql.sock:
# mv /var/lib/mysql/mysql.sock
# service mysqld
Restarting the service creates a new entry called mqsql.sock
3. 默认用户
mysqladmin -u root password 123456
Mysql –prompt –u root –p mysql
use mysql;
貌似上面这几条
4.其他ip无法连接mysql
这是因为root用户默认只允许host访问,更改为%即可
mysql>
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select host,user from user where user='root';
mysql>select host,user from user where user='root';
============================================