MySQL 管理方法

举报
江湖有缘 发表于 2023/03/21 12:58:20 2023/03/21
【摘要】 MySQL 管理方法

MySQL 管理方法

一、Mysql介绍

二、Mysql启动

三、Mysql用户管理

一、Mysql介绍
MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。目前MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。

二、Mysql启动
1.检查mysql是否启动

[root@control data]# ps -ef | grep mysqld
root       7856   2569  0 22:28 pts/0    00:00:00 grep --color=auto mysqld

2.查看mysql状态并启动

[root@control data]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@control data]# systemctl status mysqld.service 
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-04-26 22:30:14 CST; 7s ago
  Process: 8039 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 7960 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status>
  Process: 7936 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 7997 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 38 (limit: 24900)
   Memory: 418.5M
   CGroup: /system.slice/mysqld.service
           └─7997 /usr/libexec/mysqld --basedir=/usr

mysql进程查看

[root@control data]# ps -ef | grep mysqld
mysql      7997      1  2 22:30 ?        00:00:01 /usr/libexec/mysqld --basedir=/usr
root       8085   2569  0 22:31 pts/0    00:00:00 grep --color=auto mysqld

三、Mysql用户管理
1.验证登录mysql
①查看mysql版本

[root@control bin]# mysqladmin --version
mysqladmin  Ver 8.0.13 for Linux on x86_64 (Source distribution)

②跳过mysql登录密码

[root@control ~]# vim /etc/my.cnf
[root@control ~]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#

[client-server]

[mysqld]
explicit_defaults_for_timestamp=true
skip-grant-tables

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d


③修改密码

[root@control ~]# systemctl restart mysqld.service 
[root@control ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.13 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> 
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.08 sec)

mysql> exit
Bye


去掉/etc/my.cnf添加内容,重启服务

[root@control ~]# vim /etc/my.cnf
[root@control ~]# systemctl restart mysqld.service 

④登录mysql进行测试

[root@control ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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>  
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。