使用此命令首先确保你的mysql运行环境已经搭建好

这是客户端连接mysql服务器的指令,比较全的写法是下面两种

第一个是全拼,第二个是第一个的缩写

mysql --host=localhost --user=myname --password=password mydb

mysql -h localhost -u myname -ppassword mydb

一般在使用中,我们会省略-h参数,mysql会自动默认为本地连接

还有一点就是各个参数之间是否有空格的问题,-u后面可以有也可以省略空格,对于-p后面的参数我要单独说一下

这是我从mysql官方文档拷过来的内容

for password options, the password value is optional:

  If you use a -p or --password option and specify the password value, there must be no space between -p or --password= and the password following it.

  If you use a -p or --password option but do not specify the password value, the client program prompts you to enter the password. The password is not displayed as you enter it. This is more secure than giving the password on the command line. Other users on your system may be able to see a password specified on the command line by executing a command such as ps auxw.

具体就是:对于password选项,此选项是可选的

如果你明确指定了-p或者--password的值,那么-p或者--password和密码值之间是不能有空格的。

如果你使用了-p或者--password选项但是没有给出password值,客户端程序提示您输入密码。

For mysql, the first nonoption argument is taken as the name of the default database. If there is no such option, mysql does not select a default database.

对于MySQL,第一个非选项参数被当作默认数据库的名称。如果没有这样的选项,MySQL就不会选择默认数据库。

也就是说在命令行中,你的mysql密码和-p或者--password参数之间有空格,mysql会认为你输入的是登录mysql后自动选择的数据库,而不是你所期望的密码

当然命令行连接数据库还有其它参数,这里主要介绍几个经常使用的,其它请参考https://dev.mysql.com/doc/refman/5.5/en/connecting.html

mysql -u root -p 解释的更多相关文章

  1. windows下的mysql忘记root密码的解决方法

    1.首先,需要关闭MySQL Server服务.在"运行"窗口,输入"services.msc",进入"服务"窗口. 2. 在服务窗口,可以 ...

  2. linux下误删mysql的root用户,解决方法

    开始对liunx界面不熟悉,可能由于不小心,把root误删了,怎么办? 1. # killall mysqld    干掉所有mysql进程 2. # mysqld_safe --skip-grant ...

  3. mysql忘记root密码怎么办?

    有时候忘记mysql的root密码了,怎么办? 这个时候,我们可以修改my.cnf,添加以不检查权限的方式启动,再修改root,最后重启mysql数据库. (1)service mysql stop ...

  4. MySQL修改root密码的多种方法

    不知道在cmd模式下是不是区分大小写,我大写成功了,小写没成功,不知是我拼写的错误,还是区分大小写!!?? 方法1: 用SET PASSWORD命令 mysql -u root mysql> S ...

  5. Mysql修改root密码

    一.启动命令行,输入: taskkill /f /im mysqld.exe //关闭mysql 二.转入mysql的bin目录下 三.输入:mysqld --skip-grant-tables // ...

  6. windows下新安装的mysql修改root password问题

    常用步骤: 1. 在my.ini中的mysqld下添加一行 skip-grant-tables 2.重启mysql后直接进入后,用SQL直接修改password列: C:\> net stop ...

  7. 忘记Mysql的root密码怎么办?

    有时候忘掉了mysql的root密码,这种情况下,如何重置root的密码呢? 找到并编辑mysql的my.ini配置文件,在mysqld节点中添加上skip-grant-table. 如下: [mys ...

  8. MySQL修改root账号密码

    MySQL数据库中如何修改root用户的密码呢?下面总结了修改root用户密码的一些方法   1: 使用set password语句修改 mysql> select user(); +----- ...

  9. mac 安装mysql + 修改root用户密码 + 及报Access denied for user 'root'@'localhost' (using password:YES)解决办法

    1.下载MySQL 到mysql的官网http://dev.mysql.com/downloads/mysql/然后在页面中会看到“MySQL Community Server”下方有一个“downl ...

随机推荐

  1. bzoj1004 [HNOI2008]Cards【Burnside/Polya】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 一道好题,但并不是好在融合了三个“考点”(计数,背包dp,逆元),其实背包dp以及求逆 ...

  2. spark_运行spark-shell报错_javax.jdo.JDOFatalDataStoreException: Unable to open a test connection to the given database.

    error: # ./spark-shell Caused by: javax.jdo.JDOFatalDataStoreException: Unable to open a test connec ...

  3. 【ACM】取石子 - 博弈论

    取石子(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而由于条件有限,他/她们是用旺仔小馒头当作石子.游 ...

  4. 系统启动与Linux的初始化_1

    boot 的起源: the term bootstrap refers to a person who tries to stand up by pulling her own boots. (Und ...

  5. Spring Cloud下使用Feign Form实现微服务之间的文件上传

    背景 ​ Spring Cloud现在已经被越来越多的公司采用了,微服务架构比传统意义上的单服务架构从复杂度上多了很多,出现了很多复杂的场景.比如,我们的产品是个app,支持第三方登录功能,在手机端调 ...

  6. nginx中文手册内容说明

    1.什么是nginx? Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性: 作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接, ...

  7. D2 前端会议

    D2 前端会议 时间 2019年1月6日 图片

  8. java 基础 04 循环结构 一维数组

    内容: (1)循环结构 (2)一维数组 1.循环结构 1.1for循环 (1)语法格式 for(初始化表达式1;条件表达式2;修改初始化表达式3){ 循环体; } (2)执行流程 执行初始化表达式 = ...

  9. 从零开始的全栈工程师——js篇2.5

    数据类型与全局属性 js的本质就是处理数据 数据来自于后台的数据库所以变量就起到一个临时存储数据的这作用ECMAscirpt 制定了js的数据类型 一.数据类型 1.基本数据类型 基本数据类型就是简单 ...

  10. SpringBoot的优缺点

    优点: 1.快速构建项目 2.对主流开发框架的无配置继承 3.项目可独立运行,无须外部依赖Servlet容器 4.提高运行时的应用监控 5.极大地提高了开发.部署效率 6.与云计算的天然集成 缺点: ...