CentOS 安装Mysql

[ 2012-11-18 16:59:46 | 作者: admin ]
字号: | |
安装
我们利用liunx yum来安装mysql,yum -y install mysql mysql-server;相应的卸载命令是 yum -y remov xxxx

设置账号
安全完成后,我们利用mysqladmin -u root password ‘123456’ 命令进入mysql,报了error 1045错误,访问被拒绝

解决办法是重新设置root用户密码,在Windows平台下操作步骤如下:

1. 杀掉所以mysql的进程

        killall mysqld

2. 查看mysql状态

        /etc/rc.d/init.d/mysqld status

3.安全模式下面进入mysql

        mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

        屏幕出现: Starting demo from .....

4. 新开起一个终端输入

        mysql -u root mysql

5.设置 root 用户的密码

        mysql> update user set password=password('123456') where user='root'

6. 记得要这句话,否则如果关闭先前的终端,又会出现原来的错误

            FLUSH PRIVILEGES;

7.关闭mysql

          mysql> quit

8.启动mysql

          /etc/rc.d/init.d/mysqld start

9.mysql -u root -p(会让你输入刚设置的密码)

打开端口
在CentOS系统中防火墙默认是阻止3306端口的,我们要是想访问mysql数据库,我们需要这个端口,命令如下:

1.在iptables 加入运行访问3306

          /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

2.保存

        /etc/rc.d/init.d/iptables save

3.重新启动iptables

      /etc/rc.d/init.d/iptables restart

4.查看iptables状态

      /etc/init.d/iptables status

远程访问
mysql不允许远程用户访问主机服务器 1130
安装完之后成 使用 mysql admin连接报错
ERROR 1130: Host ***.***.***.*** is not allowed to connect to this MySQL server
以下百度查到的,试过可以
说明所连接的用户帐号没有远程连接的权限,只能在本机(localhost)登录。
需更改 mysql 数据库里的 user表里的 host项
把localhost改称%
具体步骤:登陆到mysql
首先 use mysql;
按照别人提供的方式update的时候,出现错误。
mysql> update user set host='%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
然后查看了下数据库的host信息如下:
mysql> select host from user where user = 'root';
+-----------------------+
| host |
+-----------------------+
| % |
| 127.0.0.1 |
| localhost.localdomain |
+-----------------------+
3 rows in set (0.00 sec)
host已经有了%这个值,所以直接运行命令:
mysql>flush privileges;
再用mysql administrator连接...成功!!!
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1904

这篇日志没有评论。

此日志不可发表评论。