设为首页收藏本站 JeeStudy企业开发官网①

JEE Study|JAVA EE|企业级开发学习网

 找回密码
 立即加入

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 1599|回复: 0
打印 上一主题 下一主题

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

[复制链接]

219

主题

221

帖子

1418

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1418

最佳新人活跃会员热心会员推广达人宣传达人灌水之王突出贡献优秀版主荣誉管理论坛元老

跳转到指定楼层
楼主
发表于 2020-4-3 17:27:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
mysql 命令


查看MySQL命令的选项:[root@CentOS8 ~]# mysql --help


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


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


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


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


执行结果:
[Shell] 纯文本查看 复制代码
[root@CentOS8 ~]# 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.

[Shell] 纯文本查看 复制代码
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 服务没有启动。
启动方法:[root@CentOS8 init.d]# ./mysql.server start



知识改变命运!

JAVA EE 学习     JAVA EE 资料
JEE Study:企业级开发学习网!
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

QQ|Archiver|手机版|小黑屋|JEE Study ( 京ICP备16036936   JeeStudy企业开发官网①

GMT+8, 2024-5-20 15:18 , Processed in 0.216851 second(s), 27 queries .

Powered by JeeStudy!

© 2008-2020 JEE Study 企业级开发学习网

快速回复 返回顶部 返回列表