一.安装配置
1.1 检查是否已安装 mysql
rpm -qa |grep mysql
1.2 卸载自带 mysql-libs-5.1.73-7.el6.x86_64
rpm -ev --nodeps mysql-libs-5.1.73-7.el6.x86_64
1.3 安装
sudo yum -y install mysql-server
(卸载使用yum命令安装的mysql: yum remove mysql mysql-server mysql-libs compat-mysql51
检查残留文件,如有则删除: find / -name mysql )
1.4 字符集配置
sudo vim /etc/my.cnf
在[mysqld]节点下添加
default-character-set=utf8
character-set-server=utf8
1.5 自启动配置
sudo chkconfig mysqld on
sudo chkconfig --list mysqld 查看(如果2-5位启用状态on则ok)
1.6 防火墙增加3306端口
sudo vim /etc/sysconfig/iptables
-A INPUT -p TCP -m TCP --dport 3306 -j ACCEPT
重启防火墙 sudo service iptables restart
1.7 常用命令
启动 sudo service mysqld start
关闭 sudo service mysqld stop
重启 sudo service mysqld restart
二.账号设置
2.1 重新启动 mysql, 首次登陆 mysql
sudo service mysqld restart
mysql -u root
2.2 查看目前mysql的用户
select user,host,password from mysql.user;
2.3 修改root密码,password('') 注意是引号里面写新密码
set password for root@localhost=password('*******‘);
set password for root@centos=password('*******');
set password for root@127.0.0.1=password('*******');
2.4 使用账号密码登陆
mysql -u root -p
2.5 删除匿名用户
查看 select user,host from mysql.user;
删除 delete from mysql.user where user='';
再次查看 select user,host from mysql.user;
刷新,使以上操作生效:flush privileges;
2.6 插入mysql新用户XXX和密码XXX
insert into mysql.user(host,user,password) values ("localhost","XXX",password("XXX"));
刷新,使以上操作生效:flush privileges;
2.7 创建新的database
create database`XXmall` default character set utf8 collate utf8_general_ci;
2.8 database 对本地用户XXX赋予所有权限
grant all privileges on XXmmall.* to XXX identified by 'XXX';
2.9(可选)如果有需要,就给账号XXX开通外网权限
开放外网全部权限
grant all privileges on XXmmall.* to 'XXX'@'%' identified by 'XXX';
可以根据情况开通权限,增删改查,账号及IP
grant select,insert,update on mmall.* to XXX@'192.168.?.?' identified by 'XXX';
刷新,使以上操作生效:flush privileges;