首页 > 代码库 > mysql安装和基本配置-redhat
mysql安装和基本配置-redhat
1.redhat yum替换参考
url:http://blog.csdn.net/zcyhappy1314/article/details/17580943
2.yum卸载mysql
rpm -qa|grep -i mysql
yum remove mysql mysql-server mysql-libs;
或
rpm -ev MySQL-server-4.0.14-0 MySQL-client-4.0.14-0
卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除
rm -f /etc/my.cnf
rm -rf /var/lib/mysql
3.yum 安装mysql
[root@sample ~]# yum -y install mysql-server ← 安装MySQL
参考 url:http://evanlinux.blog.51cto.com/7247558/1374023
4.配置MySQL
[root@sample ~]#vim /etc/my.cnf ← 编辑MySQL的配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
old_passwords=1
default-character-set=utf8 ← 添加这一行
5.查看端口3306
lsof -i:3306
6.防火墙开放端口3306
vim /etc/sysconfig/iptables
增加一行
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
使其生效
service iptables restart
/etc/rc.d/init.d/iptables save
7.启动mysql
[root@sample ~]#/etc/rc.d/init.d/mysqld start ← 启动MySQL服务
或者
[root@sample ~]# service mysqld start
8.允许mysql外网访问
use mysql;
select host,user from user;
update user set host=‘%‘ where user=‘root‘ and host=‘localhost‘;
flush privileges;
这个时候就可以使用图形管理工具访问了。。。。
9.之后可能会遇到这个错误
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
做如下操作:
service mysqld stop
mysqld_safe --skip-grant-tables --skip-networking &
use mysql;
select host,user,password from user;
delete from user where host!=‘%‘
10.设置root密码
MySQL在刚刚被安装的时候,它的root用户是没有被设置密码的。首先来设置MySQL的root密码。
[root@sample ~]# mysql -u root ← 用root用户登录MySQL服务器
mysql> UPDATE user SET Password=PASSWORD(‘963852‘) where USER=‘root‘ and host=‘%‘;
或
mysql>grant all on mysql.* to ‘root‘@‘localhost‘ identified by ‘password‘;
或
mysql> set password for ‘root‘@‘localhost‘ =password(‘123456‘);
之后 就可以通过密码登录mysql了。
11.权限设置
任意主机以用户root和密码mypwd连接到mysql服务器,拥有所有数据库的所有表进行所有操作的权限
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘963852‘ WITH GRANT OPTION;
mysql> flush privileges;
mysql安装和基本配置-redhat