JeeStudy 发表于 2020-4-3 17:27:10

MySQL8.0大师之路:第9章:MySQL教程-9.1 MySQL从服务器连接与断开

mysql 命令


查看MySQL命令的选项:# mysql --help


连接MySQL命令:shell> mysql -h host -u user -p


-h:host 服务器的主机名
-u:user 登录服务器的用户
-p:password 密码


如果是登录本机,-h 可以省略


回车执行后提示输入密码:
Enter password:


执行结果:
# mysql -p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

Copyright (c) 2000, 2020, 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已准备就绪,可以输入SQL语句。




提示:如果是用随机密码登录,首次执行SQL相关语句时,需要修改密码:
mysql> show databases;      
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user user() identified by '123';
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database         |
+--------------------+
| information_schema |
| mysql            |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)



注意:有些数据库是允许匿名登录的,所以可以执行数据mysql命令登录:
shell> mysql






与MySQL服务器断开:使用命令 quit 或者 \q
mysql> quit
Bye
在Unix 或Linux上可以使用快捷键 Ctrl+D 直接断开。


常见错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

MySQL 服务没有启动。
启动方法:# ./mysql.server start

页: [1]
查看完整版本: MySQL8.0大师之路:第9章:MySQL教程-9.1 MySQL从服务器连接与断开