1.(访问账号权限控制)dql-查询(select) dml-(insert update delete) ddl-(create table create view) dcl-(grant)
2.(访问地址权限控制)sudo yum -y in
3.安装mysql:sudo yum -y install mysql-server,打开/etc/my.cnf加入:default-character-set = utf8
4.设置mysql随系统自动启动:sudo chkconfig mysqld on然后检查下:sudo chkconfig --list mysqld如果2~5都是on为成功
5.启动mysql:sudo service mysqld start
Starting mysqld: [ OK ]
启动成功
6.用户登录下:mysql -u root(第一次登录不需要密码不加-p)
7.查看用户:select user,host from mysql.user;
8.防火墙开放3306接口,mysql使用:sudo vim /etc/sysconfig/iptables;重启防火墙:sudo service iptables restart
9.初始化mysql数据库后无法看到mysql.usr表,解决方案:重置密码
mysqladmin -uroot -pshapolang password 123456
(2018年1月24解决:原因是命令写错了:show databases;)
10.查看数据:select user, host from mysql.user;
11.删除匿名用户:delete from mysql.user where user='';
常用命令:
刷新权限:flush privileges;
查看数据库:show databases;
设置密码的多种方法:
方法1: 用SET PASSWORD命令
mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法2:用mysqladmin
mysqladmin -u root password "newpass"
如果root已经设置过密码,采用如下方法
mysqladmin -u root password oldpass "newpass"
方法3: 用UPDATE直接编辑user表
mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丢失root密码的时候,可以这样
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
11.插入用户mmall:insert into mysql.user(Host,User,Password) values("localhost","mmall",password("mmall"))
12.查看是否生效:select user,host from mysql.user(请使用root用户登录数据库)
13.创建数据库:create database `mmall` default character set utf8 collate utf8_general_ci;
14.查看权限:select * from mysql.user G; (G格式化)
15.权限复制到mmall:grant all privileges on mmall.* to mall@'%' identified by 'mmall' with grant option;(all privileges所有权限可换成select,delete,create等等,mmall.*代表这个数据库,@符号之后是ip,%是指所有ip)
******
mysql常用命令: service mysqld restart-重启