Linux下安装MySQL5.x

10/16/2021 mysql

# Linux下安装MySql5.x步骤✨

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
# 或
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
# service mysqld restart
# mysql -uroot
> SET PASSWORD FOR root@localhost = password('密码'); # 上引号复制后仍是中文

# mysq5版本设置远程访问mysql,所有操作、以root用户、所有ip来源
> grant all privileges on *.* to 'w2personnel'@'%' identified by 'w2personnelsys';
> flush privileges;

# 查看服务是否启动:
> service mysqld status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 常用命令🧨

#设置安全选项:
mysql_secure_installation

#关闭MySQL
systemctl stop mysqld 

#重启MySQL
systemctl restart mysqld 

#查看MySQL运行状态
systemctl status mysqld 

#设置开机启动
systemctl enable mysqld 

#关闭开机启动
systemctl disable mysqld

#查看版本
select version();

# 修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xhxt42';
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# MySql安装常见错误💢

# 1142错误

1142 - SELECT command denied to user 'root_ssm'@'localhost' for table 'user'

# 错误信息的字面意思是:表“user”拒绝用户“root_ssm”@“localhost”的SELECT命令 ,很明显用户没有查看user表的权限,用管理员账号给他授权就行了
1
2
3

# 解决方案

1、使用客户端授权(Navicat Premium 12)

-- 使用root用户登陆mysql
use mysql;

select * from user where user='user';

-- SQL语句where后面的条件写要授权的那个用户名
1
2
3
4
5
6

mysql1001

**上图标红的地方的值为‘N’,表示没有权限,将其改为Y就行了。**

2、使用Mysql的命令行客户端

mysql1002

use mysql;

select * from user where user='w2user';
1
2
3

mysql1003

修改root用户的localhost权限

update user set Select_priv='Y' where user='middleuser';

-- 根据查询结果中的列名,一个一个的写update语句修改,
-- 全部改好后再刷新MySQL的系统权限相关表:
flush privileges;
1
2
3
4
5
十年
陈奕迅