使用此命令首先确保你的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. 15-----jQuery补充

    jquery除了咱们上面讲解的常用知识点之外,还有jquery 插件.jqueryUI知识点 jqueryUI 官网: https://jqueryui.com/ jqueryUI 中文网: http ...

  2. Unity PlayerPrefs

    对于游戏存档,储存最高分,排行榜都需要用到储存,现在存储的方式有很多,可以存本地的Json,XML,Sqlite,还有一种就是unity自带的一种存储PlayerPrefs. 那么这个PlayerPr ...

  3. web应用框架Django

    一.安装Django 打开网址https://www.djangoproject.com/download/进行查看 二.创建项目 打开命令行,进入想要安置项目的目录 命令行输入:django-adm ...

  4. python学习四(处理数据)

    head first python中的一个数据处理的例子 有四个U10选手的600米成绩,请取出每个选手跑的最快的3个时间.以下是四位选手的9次成绩 James 2-34,3:21,2.34,2.45 ...

  5. Access 将SQL查询结果强制转换为某种类型

    每个函数都可以强制将一个表达式转换成某种特定数据类型. 语法 CBool(expression) CByte(expression) CCur(expression) CDate(expression ...

  6. Linux Mint下的conky配置

    最近闲来无事,想把自己的Linux Mint弄的再炫酷点,在桌面上显示一些信息,因为我已经装了Cairo-dock,现在就差这个了,下面简单说下整个流程,首先你得安装conky, sudo apt-g ...

  7. cd进入相关目录的命令

    今天不记得怎么进入Linux的根目录了,查询了下顺便复习下其他命令: 1.[root@localhost]#cd /usr 切换至根目录下的文件夹要加"/" 2.[root@loc ...

  8. bootstrap中使用modal加载kindeditor时弹出层文本框不能输入的问题

    答案来自老外http://stackoverflow.com/questions/14795035/twitter-bootstrap-modal-blocks-text-input-field $( ...

  9. Servlet的生命周期以及线程安全问题

    一:Servlet生命周期图,以及注意事项 二:代码演示 LifeCycleServlet.java package cn.woo.servlet; import java.io.IOExceptio ...

  10. 【Java】Maven 常用命令

    Maven 常用命令 mvn compile 编译,生成target文件夹,里边有classes文件夹,存放.class文件 mvn test 执行测试 mvn package 打包,在targert ...