Open xgqfrms opened 1 year ago
https://www.cnblogs.com/xgqfrms/p/13570542.html
MySQL Community Server 8.0.21
# version
$ mysqladmin --version
# 8.0.21
$ mysql --version
# mysql Ver 8.0.21 for osx10.15 on x86_64 (Homebrew)
$ mysqladmin --version
# mysqladmin Ver 8.0.21 for osx10.15 on x86_64 (Homebrew)
https://dev.mysql.com/downloads/mysql/
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.31-macos12-x86_64.dmg
libmysqlclient
Sql@2022
mysqladmin --version
zsh: command not found: mysqladmin
vim ~/.zshrc
code ~/.zshrc
export PATH=${PATH}:/usr/local/mysql/bin/
export PATH=${PATH}:/usr/local/mysql/bin/
source ~/.zshrc # If you use Oh-My-Zsh
source ~/.bashrc # If you use Default Bash
vim ~/.zshrc
code ~/.zshrc
export PATH=${PATH}:/usr/local/mysql/bin/
export PATH=${PATH}:/usr/local/mysql/bin/
source ~/.zshrc # If you use Oh-My-Zsh
source ~/.bashrc # If you use Default Bash
update VSCode ✅
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'
https://zhuanlan.zhihu.com/p/48600691
提示 'root'@'localhost'有误,查询发现root
对应的host
是%
# 开通权限
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# 刷新授权
mysql> flush privileges;
# sql@2022 ✅
➜ ~ mysql -u root -h 192.168.18.195 -P 3306 -p
Enter password:
https://www.cnblogs.com/yang842718540/p/9205424.html
var mysql = require('mysql');
var connection = mysql.createConnection({
//host为目标实例的连接地址。
host : 'dpxxxx-xxxxxxxx.proxy.dms.aliyuncs.com',
//user为您的AccessID。可在安全访问代理页面的被授权人列表中查看。
user : 'AccessID',
//password为您的AccessSecret。可在安全访问代理页面的被授权人列表中查看。
password : 'AccessSecret',
//port为目标实例的端口号。
port : '3306',
//database为目标实例的数据库名称。
database : 'schema'
});
connection.connect();
//使用execute方法执行SQL语句。
// 本示例以SHOW DATABASES为例,您也可以换成其他SQL语句。
connection.query('SHOW DATABASES', function(err, result) {
console.log(result);
});
connection.end();
mysql connect from remote host
mysql connect from command line
https://www.digitalocean.com/community/tutorials/how-to-allow-remote-access-to-mysql
$ mysql -u user -h database_server_ip -p
https://stackoverflow.com/questions/15872543/access-mysql-remote-database-from-command-line
$ mysql -u {username} -p'{password}' \
-h {remote server ip or name} -P {port} \
-D {DB name}
# For example
$ mysql -u root -p'sql@2022' -h 127.0.0.1 -P 3306 -D test
$ mysql -u root -p
✅
$ mysql -u root -h localhost -P 3306 -p
✅
$ mysql -u root -h 192.168.18.195 -P 3306 -p
❌
sql@2022
mysql -u root -h 192.168.18.195 -P 3306 -p
Enter password:
ERROR 1130 (HY000): Host '192.168.18.207' is not allowed to connect to this MySQL server
mysql -u root -h 192.168.18.195 -P 3306 -p
Enter password:
ERROR 1130 (HY000): Host '192.168.18.195' is not allowed to connect to this MySQL server
# 开通权限
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'sql@2022';
# ??? ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
mysql> SET PASSWORD FOR 'root'@'%' = PASSWORD('sql@2022');
# ERROR 1064 (42000): You have an error in your SQL syntax;
# check the manual that corresponds to your MySQL server version for the right syntax to use near 'PASSWORD('sql@2022')' at line 1
# 刷新授权
mysql> flush privileges;
mysql> use mysql;
mysql> select user,host from user;
mysql> select user,host from user \G;
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
# help
mysql> ?
For information about MySQL products and services, visit:
http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
https://shop.mysql.com/
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
query_attributes Sets string parameters (name1 value1 name2 value2 ...) for the next query to pick up.
ssl_session_data_print Serializes the current SSL session data to stdout or file
For server side help, type 'help contents'
mysql>
# 查看状态
mysql> status;
--------------
mysql Ver 8.0.31 for macos12 on x86_64 (MySQL Community Server - GPL)
Connection id: 21
Current database: mysql
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server version: 8.0.31 MySQL Community Server - GPL
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /tmp/mysql.sock
Binary data as: Hexadecimal
Uptime: 16 hours 44 min 8 sec
Threads: 2 Questions: 54 Slow queries: 0 Opens: 176 Flush tables: 3 Open tables: 97 Queries per second avg: 0.000
--------------
mysql>
mysql_native_password
vs caching_sha2_password
mysql> 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
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
$ mysql -uroot -p
Enter password:
mysql> show databases;
mysql> use mysql;
mysql> show tables;
mysql> select user, host, plugin from user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| root | % | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
mysql> create user `dev`@`%` identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> select user, host, plugin from user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| dev | % | caching_sha2_password |
| root | % | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
5 rows in set (0.00 sec)
mysql> alter user `dev`@`%` identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> select user, host, plugin from user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| dev | % | mysql_native_password |
| root | % | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
5 rows in set (0.00 sec)
# ❌
GRANT ALL ON *.* TO `developer`@`127.0.0.1` IDENTIFIED BY 'passowrd' WITH GRANT OPTION;
# ✅ 创建用户
CREATE USER `developer`@`%` IDENTIFIED BY '123456';
# ✅ 授权
GRANT ALL ON *.* TO `developer`@`%` WITH GRANT OPTION;
# 加密连接方式 plugin 不对,修改一下
# ✅ 修改授权
ALTER USER 'developer'@'%' IDENTIFIED WITH mysql_native_password BY '123456'
# 最后要刷新权限 ✅
FLUSH PRIVILEGES;
<details>
<summary>点击展开代码</summary>
<div>code...</div>
</details>
<details>
& <summary>
markdown & github
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary
macOS & MySQL 8.x
https://www.cnblogs.com/xgqfrms/tag/MySQL/default.html?page=1
https://www.cnblogs.com/xgqfrms/p/16791658.html
登录 MySQL
https://www.runoob.com/mysql/mysql-install.html#:~:text=%E5%8D%B3%E5%8F%AF%E5%90%AF%E5%8A%A8%20mysql%E3%80%82-,%E7%99%BB%E5%BD%95%20MySQL,-%E5%BD%93%20MySQL%20%E6%9C%8D%E5%8A%A1
MySQL 8.x 远程登录不了问题及解决方案
https://www.jianshu.com/p/435307de1c29