ToB企服应用市场:ToB评测及商务社交产业平台

标题: mysql,mariadb,postgresql创建用户和授权的命令 [打印本页]

作者: 徐锦洪    时间: 2024-12-28 11:23
标题: mysql,mariadb,postgresql创建用户和授权的命令
mysql,mariadb,postgresql创建用户和授权的命令
  1. 在10.1.1.11上访问,有客户端-->OK
  2. mysql -h10.1.1.44 -uroot -P3306 -plianShi20@!
  3. 一、mariadb:
  4. mysql -h10.1.1.11 -uroot -P3306 -plianShi20@!
  5. SELECT user,plugin FROM mysql.user;
  6. 一、
  7. mysql新增用户和授权(必须在服务器44上)
  8. mysql -uroot -P3306 -p
  9. 输入密码:lianShi20@!
  10. create user user1@'%' identified by 'lianShi2021';
  11. grant all privileges on *.* to user1@'%';
  12. create user user2@'%' identified by 'lianShi2021';
  13. grant all privileges on *.* to user2@'%';
  14. FLUSH PRIVILEGES;
  15. #查询用户
  16. SELECT user, host FROM mysql.user;
  17. #mysql的用户登录-->OK  lianShi2021
  18. mysql -uuser1 -P3306 -p
  19. mysql -uuser2 -P3306 -p
  20. #修改密码:
  21. SET PASSWORD FOR 'user1' = '123456';
  22. SET PASSWORD FOR 'user2' = '123456';
  23. FLUSH PRIVILEGES;
  24. GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'lianShi20@!' WITH GRANT OPTION;
  25. ALTER USER 'user1'@'%' IDENTIFIED BY 'lianShi2021' PASSWORD EXPIRE NEVER;
  26. ALTER USER 'user1'@'%' IDENTIFIED WITH mysql_native_password BY 'lianShi2021';
  27. FLUSH PRIVILEGES;
  28. ALTER USER 'user2'@'%' IDENTIFIED BY 'lianShi2021' PASSWORD EXPIRE NEVER;
  29. ALTER USER 'user2'@'%' IDENTIFIED WITH mysql_native_password BY 'lianShi2021';
  30. FLUSH PRIVILEGES;
  31. alter user  'user1'@'%' identified with mysql_native_password by 'lianShi2021';
  32. alter user  'user2'@'%' identified with mysql_native_password by 'lianShi2021';
  33. FLUSH PRIVILEGES;
  34. GRANT ALL PRIVILEGES ON *.* TO  'user1'@'%'  IDENTIFIED BY 'lianShi2021';
  35. FLUSH PRIVILEGES;
  36. 二、mariadb:新增用户和授权(必须在服务器11上)
  37. mysql -uroot -P3306 -p
  38. 输入密码:lianShi20@!
  39. create user user1@'%' identified by 'lianShi2021';
  40. grant all privileges on *.* to user1@'%';
  41. create user user2@'%' identified by 'lianShi2021';
  42. grant all privileges on *.* to user2@'%';
  43. FLUSH PRIVILEGES;
  44. mariadb的用户登录-->OK  lianShi2021
  45. mysql -uuser1 -P3306 -p
  46. mysql -uuser2 -P3306 -p
  47. 三、tidb:新增用户和授权(必须在服务器44上)
  48. mysql -h10.1.1.44 -uroot -P4000  -p
  49. 输入密码:lianshi
  50. CREATE USER 'user1'@'%' IDENTIFIED BY 'lianShi2021';
  51. grant all privileges on *.* to user1@'%';
  52. CREATE USER 'user2'@'%' IDENTIFIED BY 'lianShi2021';
  53. grant all privileges on *.* to user2@'%';
  54. FLUSH PRIVILEGES;
  55. 例子:
  56. CREATE USER 'username'@'host' IDENTIFIED BY 'password';
  57. GRANT privileges ON dbname.tablename TO 'username'@'host';
  58. GRANT ALL PRIVILEGES ON mydb.* TO 'bob'@'%';
  59. GRANT SELECT, INSERT ON mydb.mytable TO 'bob'@'%';
  60. tidb的用户登录-->OK
  61. mysql -h10.1.1.44 -uuser1 -P4000  -p
  62. mysql -h10.1.1.44 -uuser2 -P4000  -p
  63. pg:
  64. psql -h10.1.1.44 -Upostgres -dpostgres  
  65. 输入密码:lianShi20@!
  66. create user user1  with password 'lianShi2021';
  67. grant all privileges on database postgres to user1;
  68. create user user2  with password 'lianShi2021';
  69. grant all privileges on database postgres to user2;
  70. #授权user1/user2对public下表的所有操作权限
  71. GRANT USAGE ON SCHEMA public to user1;
  72. GRANT USAGE ON SCHEMA public to user2;
  73. GRANT ALL ON users TO user1;
  74. GRANT ALL ON users TO user2;
  75. #查询用户
  76. SELECT usename FROM pg_catalog.pg_user;
  77. 数据库权限查看
  78. \l
  79. #查询数据库
  80. \dt
  81. #退出
  82. \q
  83. -- 创建用户
  84. CREATE USER 'username' WITH PASSWORD 'password';
  85. -- 授权
  86. GRANT ALL PRIVILEGES ON DATABASE dbname TO 'username';
  87. create role etl_user login password 'ThePassowrd' valid until 'infinity';
  88. GRANT CONNECT ON DATABASE mydb TO etl_user;
  89. GRANT USAGE ON SCHEMA public TO etl_user;
  90. GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO etl_user;
  91. GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO etl_user;
  92. postgres的用户登录-->   lianShi2021
  93. psql -h10.1.1.44 -Uuser1 -dpostgres  
  94. psql -h10.1.1.44 -Uuser2 -dpostgres  
  95. 命令行:
  96. #查询数据库
  97. \dt
  98. #查询表
  99. select * from public.users2;
  100. 生成大文件:
  101. dd if=/dev/zero of=test69.txt bs=10M count=1
  102. df -h
  103. #查询es空间命令
  104. /home/es/elasticsearch-7.17.5/data/nodes
  105. du -sk .
  106. mariadb本机无密码登录的问题:
  107. mysql -h10.1.1.11 -uroot -P3306 -plianShi20@!
  108. mysql -h10.1.1.11 -uroot -P3306 -p
  109. SELECT User, Host,plugin FROM mysql.user WHERE User = 'root';
  110. ALTER USER root@'%'  IDENTIFIED VIA mysql_native_password;
  111. SET PASSWORD FOR 'root'@'%' = PASSWORD('lianShi20@!');
  112. ALTER USER root@'localhost'  IDENTIFIED VIA mysql_native_password;
  113. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('lianShi20@!');
  114. FLUSH PRIVILEGES;
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4