IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

四、MySQL 管理

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

文章永久连接:https://tech.souyunku.com/?p=4865

通过以下命令来检查 MySQL 服务器是否启动

ps -ef | grep mysql

例如在我的苹果电脑上运行如下

[root@localhost ~]# ps -ef | grep mysql
mysql      1520      1  0 18:21 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql      1682   1520  0 18:21 ?        00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root       1774   1744  0 18:29 pts/0    00:00:00 grep --color=auto mysql

如果 MySql 已经启动,上面的命令会输出 mysql 进程列表 mysqld_safemysqld

启动 MySQL 命令

如果 MySQL 未启动,使用以下命令来启动 MySQL 服务器

[root@localhost ~]# mysqld_safe &

关闭 MySQL 命令

如果想关闭目前运行的 MySQL 服务器, 可以执行以下命令

[root@localhost ~]# mysqladmin -u root -p shutdown
Enter password: ******

MySQL 添加用户

MySQL 服务器默认已经添加了 root 用户

如果需要添加 MySQL 用户,我们只需要在数据库 mysql 中的表 user 中插入新用户即可

下面的 SQL 语句可以添加一个新的用户

用户名为 demo 密码为 demo123 并授权用户可进行 SELECT,INSERT,UPDATE 操作权限

INSERT INTO mysql.user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'demo', PASSWORD('demo123'), 'Y', 'Y', 'Y');

然后刷新权限

FLUSH PRIVILEGES;

你可以按照下面的步骤尝试一下

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> USE  mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> INSERT INTO user (host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'demo', PASSWORD('demo123'), 'Y', 'Y', 'Y');
Query OK, 1 row affected, 4 warnings (0.01 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> SELECT host, user, password FROM user WHERE user = 'demo';
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | demo | *3055544BD641D0814B910C4ACA5799F51B80F460 |
+-----------+------+-------------------------------------------+
1 row in set (0.01 sec)

在添加用户时,请注意使用 MySQL 提供的 PASSWORD() 函数来对密码进行加密

我们在上面的范例中看到用户密码加密后为:

 3055544BD641D0814B910C4ACA5799F51B80F460

注意

1、 在 MySQL 5.7 中 user 表的 password 已换成了 authentication_string
2、 添加用户后需要执行 FLUSH PRIVILEGES 语句,这个命令执行后会重新载入授权表 如果使用该命令,无法使用新创建的用户来连接 MySQL 服务器,除非重启 MySQL 服务器

用户权限

可以在创建用户时,为用户指定权限,在对应的权限列中,在插入语句中设置为 ‘Y’ 即可

用户权限说明

命令标识 授权表中对应的列 说明
CREATE Create_priv 创建数据库、表或索引
CREATE TEMPORARY TABLES Create_tmp_table_priv 创建临时数据表
CREATE ROUTINE Create_routine_priv 创建函数或存储
CREATE VIEW Create_view_priv 创建视图
CREATE USER Create_user_priv 创建用户
EXECUTE Execute_priv 执行函数或存储过程
INDEX Index_priv 建立索引
REFERENCES References_priv 建立约束
DROP Drop_priv 删除表
SELECT Select_priv 查询数据
INSERT Insert_priv 插入数据
UPDATE Update_priv 更新数据
DELETE Delete_priv 删除数据
LOCK TABLES Lock_tables_priv 锁定表格
SHOW DATABASES Show_db_priv 列出数据库
SHOW VIEW Show_view_priv 列出视图
USAGE 只有登录权限, 其它权限都没有
ALL 所有权限,除了 WITH GRANT OPTION
ALTER Alter_priv 更改数据表
ALTER ROUTINE Alter_routine_priv 更改函数或存储过程
PROCESS Process_priv 显示连接进程和中断连接进程
FILE File_priv 载入文件
RELOAD Reload_priv 可以用 FLUSH
REPLICATION CLIENT Repl_client_priv 可以检查 Masters 和 Slaves
REPLICATION SLAVE Repl_slave_priv 在 Slave 里的特殊权限
SHUTDOWN Shutdown_priv 关闭 MySQL
WITH GRANT OPTION Grant_priv 可以将自己拥有的权限赋给其它用户
SUPER Super_priv 执行 kill 线程,change master、purge master logs、set global等命令的权限
create tablespace Create_tablespace_priv 创建表空间
Event Event_priv 确定用户能否创建、修改和删除事件
Trigger Trigger_priv 确定用户能否创建和删除触发器

GRANT 命令添加用户

下面的 SQL 语句会给指定数据库 test 添加用户 souyunku1 ,密码为 souyunku123xyz

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON test.* TO 'souyunku1'@'localhost' IDENTIFIED BY 'souyunku123xyz';

操作演示

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> USE  mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON test.* TO 'souyunku1'@'localhost' IDENTIFIED BY 'souyunku123xyz';
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> SELECT host, user, password FROM user;
+-----------------------+-------+-------------------------------------------+
| host                  | user  | password                                  |
+-----------------------+-------+-------------------------------------------+
| localhost             | root  |                                           |
| localhost.localdomain | root  |                                           |
| 127.0.0.1             | root  |                                           |
| ::1                   | root  |                                           |
| localhost             |       |                                           |
| localhost.localdomain |       |                                           |
| localhost             | demo  | *3055544BD641D0814B910C4ACA5799F51B80F460 |
| localhost             | souyunku1 | *302D386BA9E00875ADDF9ED0AD447B19FAE2FEDB |
+-----------------------+-------+-------------------------------------------+
8 rows in set (0.00 sec)

MariaDB [mysql]>

/etc/my.cnf 配置文件

一般情况下,我们不需要修改该配置文件,该文件默认配置如下:

[root@localhost ~]# cat /etc/my.cnf

显示内容如下

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

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

在配置文件中,我们可以指定不同的错误日志文件存放的目录,但一般不需要改动这些配置

干货推荐

本站推荐:精选优质专栏

附录:MySQL 教程:系列文章


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(77) 打赏



未经允许不得转载:搜云库技术团队 » 四、MySQL 管理

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367