/etc/group是用户组文件。数据表示为:组名:口令:组标识号:组内成员列表
/etc/passwd是用户文件。数据表示为:用户名:口令 :用户标识号:组标识号:注释性描述:主目录:登录shell
//检查mysql组和用户是否存在
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql
//添加mysql用户组,将用户mysql加入到mysql组中
groupadd mysql
//添加mysql用户
useradd -g mysql mysql
//修改mysql用户的登陆密码
passwd mysql
vi /etc/profile
# Mysql
export MYSQL_HOME=/home/xyp9x/mysql
export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile
修改密码(首次安装和非首次安装)
输入mysql
mysql> update mysql.user set authentication_string=password('root') where user='root';
mysql> flush privileges;
vi /etc/my.cnf,注释掉skip-grant-tables
service mysqld restart
mysql -uroot -proot
mysql> alter user user() identified by "root";
远程访问与权限(首次安装和非首次安装)
mysql> select host, user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
//指定root用户能远程连接mysql
mysql> update mysql.user set host = '%' where user = 'root';
//创建普通用户和用户密码
mysql> create user 'xyp9x'@'%' identified by 'xyp9x';
//修改指定用户密码
mysql> update mysql.user set authentication_string = password('xyp9x') where user = 'xyp9x';
//删除账户及权限
mysql> drop user 'xyp9x'@'%';
mysql> flush privileges;
//普通用户导入数据权限
mysql> select super_priv from mysql.user where user = 'xyp9x';
mysql> update mysql.user set super_priv='Y' where user = 'xyp9x';
//查看普通用户权限(无任何权限)
mysql> show grants for xyp9x;
+-----------------------------------+
| Grants for xyp9x@% |
+-----------------------------------+
| GRANT USAGE ON *.* TO 'xyp9x'@'%' |
+-----------------------------------+
//权限赋给普通用户
mysql> grant all privileges on xyp9x.* to 'xyp9x'@'%';
mysql> grant select,insert,update,delete,create on xyp9x.* to 'xyp9x'@'%';
//查看普通用户权限
mysql> show grants for xyp9x;
+--------------------------------------------------+
| Grants for xyp9x@% |
+--------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'xyp9x'@'%' |
| GRANT ALL PRIVILEGES ON `xyp9x`.* TO 'xyp9x'@'%' |
+--------------------------------------------------+
//撤销普通用户的权限
mysql> revoke all privileges on xyp9x.* from 'xyp9x'@'%';
mysql> flush privileges;
//创建数据库
mysql> create database xyp9x;
mysql> flush privileges;