MySql学习记录

MySql的配置:

字符集配置

  1. 修改/etc/my.cnf,在[mysqld]节点下
    default-character-set = utf8
    character-set-server = utf8

自启动配置

chkconfig mysqld on
chkconfig --list mysqld (如果2-5位启动on就是开启成功)

防火墙配置

修改 /etc/sysconfig/iptables添加一条
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
重启防火墙服务

用户配置

  1. MySQL查看用户
    select user,host,password from mysql.user
  2. 修改root密码:
    set password for root@localhost=password('<password>')
    set password for root@127.0.0.1=password('<password>')
  3. 删除匿名用户:
    delete from mysql.user where user='<user>';
    刷新:flush privileges
  4. 插入用户
    insert into mysql.user(Host,User,Password) values ("localhost","<yourName>",password("<yourPassword>"));
    刷新flush privileges

数据库操作

  1. 创建新的database
    create database \mmall` default character set utf8 collate utf8_general_ci`;
  2. 给本地用户赋予所有的权限
    grant all privileges on mmall.* to <youUserName>@localhost identified by <youPassword>;
  3. 给张开通外网所有权限
    grant all privileges on mmall.* to <userName>@'%' identified by <password>;
    列如:
    grant select,insert,update on mmall.* to <userName>@'192.168.1.1' identified by <password>;

dql - select
dml - insert, update, delete
ddl - create table create view
dcl - grant

推荐阅读更多精彩内容