内容更新于: 2022-06-19 02:56:28
数据库管理
前言:mysql管理,mysql停启用,mysql用户设置等内容
启动及关闭 MySQL 服务器
Windows 系统下
在 Windows 系统下,打开命令窗口(cmd),进入 MySQL 安装目录的 bin 目录。
启动:
cd c:/mysql/bin
mysqld --console
关闭:
cd c:/mysql/bin
mysqladmin -uroot shutdown
Linux 系统下
首先,我们需要通过以下命令来检查MySQL服务器是否启动:
ps -ef | grep mysqld
如果MySql已经启动,以上命令将输出mysql进程列表, 如果mysql未启动,你可以使用以下命令来启动mysql服务器:
root@host# cd /usr/bin
./mysqld_safe &
如果你想关闭目前运行的 MySQL 服务器, 你可以执行以下命令
root@host# cd /usr/bin
./mysqladmin -u root -p shutdown
Enter password: ******
MySQL 用户设置
如果你需要添加 MySQL 用户,你只需要在 mysql 数据库中的 user 表添加新用户即可。
以下为添加用户的实例,用户名为zhangsan,密码为123456,并授权用户可进行 SELECT, INSERT 和 UPDATE操作权限:
-bash-4.2# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 727
Server version: 5.7.22 MySQL Community Server (GPL)
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> use mysql;
Database changed
mysql> INSERT INTO mysql.user(Host, User, authentication_string, ssl_cipher, x509_issuer, x509_subject) VALUES ('localhost', 'zhangsan', PASSWORD('123456'), '', '', '');
Query OK, 1 row affected, 1 warning (0.00 sec);
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | mysqld |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | zhangsan |
+-----------+---------------+
4 rows in set (0.00 sec)
删除用户
DROP USER 'zhangsan'@'localhost';
参考文章
本文结束
