mysql 授权 登录 重启 关闭
2019-07-16 21:09 握瑾怀瑜 阅读(544) 评论(0) 编辑 收藏 举报用户名密码登录 root@river-NUC8i7HNK:~# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.7.26 MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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> mysql> 查看mysql用户名 和 权限 mysql> select host,user from mysql.user; +-----------+---------------+ | host | user | +-----------+---------------+ | % | test1 | | % | zt_dev | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+---------------+ 5 rows in set (0.00 sec) 查看mysql端口号 mysql> show global variables like 'port'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3306 | +---------------+-------+ 1 row in set (0.00 sec)
查看当前用户的权限 mysql> show grants; +---------------------------------------------------------------+ | Grants for zt_dev@% | +---------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'zt_dev'@'%' WITH GRANT OPTION | +---------------------------------------------------------------+ 1 row in set (0.00 sec) 退出当前用户 mysql> exit; Bye
增加一个用户(zt_dev)密码为1234 并 授权(zt_dev)用户拥有当前数据库的所有权限 mysql> grant all privileges on *.* to zt_dev@'%' identified by '1234' with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec) 刷新数据库 授权才会起作用 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
增加一个test1用户,密码为123456,可以在任何主机上登录,并授权test1拥有当前数据库的查询,增加,修改和删除的权限。需要在mysql的root用户下进行
mysql> grant select,insert,update,delete on student.* to test1@”%” identified by “123456″;
Query OK, 0 rows affected, 1 warning (0.00 sec)
刷新数据库 授权才会起作用
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
增加一个test2用户,密码为123456789,只能在192.168.2.12上登录,并授权test2拥有当前数据库的查询,增加,修改和删除的权限。需要在mysql的root用户下进行 mysql> grant select,insert,update,delete on student.* to test2@192.168.2.12 identified by “123456789″; Query OK, 0 rows affected, 1 warning (0.00 sec) 刷新数据库 授权才会起作用 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
% 可以在任何主机登录
192.168.3.111 只能在此主机上登录
localhost 只能在本地登录
使用 service 关闭:service mysql stop
[root@localhost ~]# service mysql stop Redirecting to /bin/systemctl stop mysql.service [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# ps -ef|grep mysql root 5714 5695 0 15:55 pts/1 00:00:00 mysql -u root -p root 16852 5695 0 19:56 pts/1 00:00:00 grep --color=auto mysql [root@localhost ~]# [root@localhost ~]#
使用 service 启动:service mysql start [root@localhost ~]# service mysql start Redirecting to /bin/systemctl start mysql.service [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# ps -ef|grep mysql root 5714 5695 0 15:55 pts/1 00:00:00 mysql -u root -p mysql 16888 1 0 19:56 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr mysql 17054 16888 2 19:56 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock root 17082 5695 0 19:57 pts/1 00:00:00 grep --color=auto mysql
使用 service 重启:service mysql restart
[root@localhost ~]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service
linux下开启 关闭 重启 mysql
使用 service 启动:service mysql start
使用 service 关闭:service mysql stop
使用 service 重启:service mysql restart
Linux下 MySQL通过source命令执行sql文件(数据库表结构和数据)
spurce + .sql文件路径(可百度看详细)
加油的人生不解释