groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql &
# Next command is optional
cp support-files/mysql.server /etc/init.d/mysql.server
service mysql.server restart 启动
修改默认密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY ‘Abcde.123';
创建用户赋予权限:
CREATE USER ‘username'@'%' IDENTIFIED BY 'password';
授权
GRANT privileges ON databasename.tablename TO ‘username’@'host'
privileges:用户的操作权限,如SELECT,INSERT,UPDATE等,如果要授予所的权限则使用ALL
databasename:数据库名
tablename:表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*表示,如*.*
用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
修改用户名密码:
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');
如果是当前登陆用户用:
SET PASSWORD = PASSWORD(“newpassword");
撤销授权:
REVOKE privilege ON databasename.tablename FROM ‘username'@'host';
注意:
假如你在给用户'pig'@'%'授权的时候是这样的(或类似的):GRANT SELECT ON test.user TO 'pig'@'%',则在使用REVOKE SELECT ON *.* FROM ‘pig'@'%';命令并不能撤销该用户对test数据库中user表的SELECT 操作。
相反,如果授权使用的是GRANT SELECT ON *.* TO 'pig'@'%';则REVOKE SELECT ON test.user FROM 'pig'@'%';命令也不能撤销该用户对test数据库中user表的Select权限。
错误一:
[root@localhost ~]# systemctl start mysql.service
Failed to start mysql.service: Unit mysql.service not found.
解决:
yum install mariadb-server -y //如果已安装可以省略
systemctl start mariadb.service //启动服务
systemctl enable mariadb.service //开机启动服务
错误二:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
查找文件:
find / -name mysql.sock
如果没有:
service mysql.server restart 重新生成文件
该文件在 my.cnf 中定义
链接 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
错误三:
MySQL server PID file could not be found! [FAILED]
yum install -y mariadb-server
systemctl start mariadb.service
systemctl enable mariadb.service