三、登录MySQL

  登录MySQL的命令是mysql, mysql 的使用语法如下:
  mysql [-u username] [-h host] [-p[password]] [dbname]
  username 与 password 分别是 MySQL 的用户名与密码,mysql的初始管理帐号是root,没有密码,注意:这个root用户不是Linux的系统用户。MySQL默认用户是root,由于初始没有密码,第一次进时只需键入mysql即可。    
    root@cvskill-laptop:/# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.1.37-community MySQL Community Server (GPL)

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql> 

  出现了“mysql>”提示符,恭喜你,安装成功!
  增加了密码后的登录格式如下:
  mysql -u root -p
  Enter password: (输入密码)
  其中-u后跟的是用户名,-p要求输入密码,回车后在输入密码处输入密码。

  注意:这个mysql文件在/usr/bin目录下,与后面讲的启动文件/etc/init.d/mysql不是一个文件。

四、MySQL的几个重要目录

  MySQL安装完成后不象SQL Server默认安装在一个目录,它的数据库文件、配置文件和命令文件分别在不同的目录,了解这些目录非常重要,尤其对于Linux的初学者,因为 Linux本身的目录结构就比较复杂,如果搞不清楚MySQL的安装目录那就无从谈起深入学习。

  下面就介绍一下这几个目录。

  1、数据库目录
  /var/lib/mysql/

  2、配置文件
  /usr/share/mysql(mysql.server命令及配置文件)

  3、相关命令
  /usr/bin(mysqladmin mysqldump等命令)

  4、启动脚本
  /etc/rc.d/init.d/(启动脚本文件mysql的目录)

五、修改登录密码

  MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。

  1、命令
  usr/bin/mysqladmin -u root password 'new-password'
  格式:mysqladmin -u用户名 -p旧密码 password 新密码

  2、例子
  例1:给root加个密码123456。
  键入以下命令 :
  root@cvskill-laptop:/# /usr/bin/mysqladmin -u root password 123456
  注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。

  3、测试是否修改成功
   1)不用密码登录
    root@cvskill-laptop:/# mysql
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    root@cvskill-laptop:/# 

  显示错误,说明密码已经修改。

  2)用修改后的密码登录
    在Enter password: 之后输入密码,但linux中密码不回显。
    root@cvskill-laptop:/# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5
    Server version: 5.1.37-community MySQL Community Server (GPL)

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql> 

  成功!
  这是通过mysqladmin命令修改口令,也可通过修改库来更改口令。

posted on 2013-11-13 19:44  deogao  阅读(123)  评论(0编辑  收藏  举报