Linux系统之Mysql数据库用户基本管理

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: Linux系统之Mysql数据库用户基本管理

一、检查本地系统版本

[root@node ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

二、检查mysql服务状态

[root@node ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-11-05 15:55:26 CST; 3h 17min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 57435 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 57412 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 57437 (mysqld)
    Tasks: 28
   Memory: 217.3M
   CGroup: /system.slice/mysqld.service
           └─57437 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Nov 05 15:55:23 node systemd[1]: Starting MySQL Server...
Nov 05 15:55:26 node systemd[1]: Started MySQL Server.

三、测试本地连接mysql

[root@node ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> 

四、新增mysql数据库用户

1.用户组成介绍

admin@'%'      #   %代表0.0.0.0任意机器使用admin账号登录
admin@'192.168.100.100'    # 代表此用户只能是从192.168.200.1这台机器登录

2.新建用户

mysql> create user "admin"@"%" identified by "123456";
Query OK, 0 rows affected (0.00 sec)

五、给用户授权

mysql>  grant all on *.* to 'admin'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

六、mysql用户的基本操作

1.修改用户密码

set password for admin=password('aayya666');

2.查看用户列表

mysql> select user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| admin         | %         |
| root          | 127.0.0.1 |
| root          | ::1       |
|               | localhost |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
|               | node      |
| root          | node      |
+---------------+-----------+
9 rows in set (0.00 sec)

3.查看用户授权

mysql>  show grants for admin;
+--------------------------------------------------------------+
| Grants for admin@%                                           |
+--------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION |
+--------------------------------------------------------------+
1 row in set (0.00 sec)

4.删除用户

drop user 'admin'@'%';

七、测试远程登录mysql

[root@node ~]# mysql -h 192.168.3.166 -P3306 -uadmin -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.7.40, for Linux (x86_64) using  EditLine wrapper

Connection id:        6
Current database:    
Current user:        admin@web2.huawei.com
SSL:            Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Current pager:        stdout
Using outfile:        ''
Using delimiter:    ;
Server version:        5.7.40 MySQL Community Server (GPL)
Protocol version:    10
Connection:        192.168.3.166 via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:        3306
Uptime:            3 hours 34 min 15 sec

Threads: 1  Questions: 3268  Slow queries: 0  Opens: 299  Flush tables: 1  Open tables: 87  Queries per second avg: 0.254
--------------

mysql> 
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
关系型数据库 MySQL Linux
Linux下怎么快速部署MySQL服务,并使用
Linux下怎么快速部署MySQL服务,并使用
13 5
|
1天前
|
存储 搜索推荐 数据库
软件系统【标签tag功能】的两种数据库设计
软件系统中的标签功能可采用两种数据库设计。方案一,文章和Tag各一表,Tag信息存储在文章表内(`tags`和`tagids`字段),优点是模型简单,但查询效率低且易引发数据冗余和一致性问题。方案二,增加Tagmap表,用于存储标签-文章映射,利于索引查询和数据更新,适用于高效率需求,但结构更复杂。
8 0
软件系统【标签tag功能】的两种数据库设计
|
1天前
|
关系型数据库 MySQL Linux
Linux系统中Mysql5.7建立远程连接
Linux系统中Mysql5.7建立远程连接
4 0
|
1天前
|
关系型数据库 MySQL Linux
Linux centos 6.5 - Mysql 安装 、卸载、修改密码、忘记密码 并异常处理
Linux centos 6.5 - Mysql 安装 、卸载、修改密码、忘记密码 并异常处理
5 0
|
2天前
|
关系型数据库 MySQL Linux
linux安装mysql
linux安装mysql
|
4天前
|
存储 关系型数据库 MySQL
MySQL数据库进阶第三篇(MySQL性能优化)
MySQL数据库进阶第三篇(MySQL性能优化)
|
2天前
|
存储 关系型数据库 MySQL
关系型数据库mysql日志和临时文件
【6月更文挑战第15天】
18 4
|
2天前
|
存储 关系型数据库 MySQL
关系型数据库mysql数据文件存储
【6月更文挑战第15天】
9 4
|
2天前
|
存储 关系型数据库 MySQL
关系型数据库mysql文件系统支持
【6月更文挑战第15天】
19 4
|
3天前
|
存储 自然语言处理 关系型数据库

热门文章

最新文章