sishui198
作者sishui198·2012-08-05 11:14
软件开发工程师·Esri中国(北京)有限公司

Linux下Mysql相关问题

字数 2821阅读 2288评论 0赞 0
在linux下安装了mysql,首次登陆,用户名为root,密码默认为空,所以要对密码进行修改。
修改密码:mysqladmin -u root password +自己的密码,这样我们就修改了mysql登陆用户root的密码。
之所以这样可以做,其实这是一条修改密码的语句:

        格式:mysqladmin -u 用户名 -p 旧密码 password 新密码

         注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。

连接mysql的时候用:mysql -h localhost -u root -p
 
mysql中可能有多个数据库,但是我们在某一个时候只能使用一个,具体命令如下:
[root@liuyu ~]# mysql -h localhost -u root -p;
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 17
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)
mysql> use test;
Database changed
mysql>
 
 
 
如果忘记了Mysql的密码呢?是不是可以找过来呢?答案是肯定的,以下来自:http://www.osyunwei.com/archives/2014.html

1、编辑MySQL配置文件my.cnf
     vi /etc/my.cnf    #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables
            [mysqld]
            skip-grant-tables
            :wq!  #保存退出
            shutdown -r now   #重启系统

2、进入MySQL控制台
            mysql -uroot -p   #直接按回车,这时不需要输入root密码。

3、修改root密码

     update mysql.user set password=password('123456') where User="root" and Host="localhost";
           flush privileges;  #刷新系统授权表

4、取消/etc/my.cnf中的skip-grant-tables
           vi /etc/my.cnf   编辑文件,找到[mysqld],删除skip-grant-tables这一行
           :wq!  #保存退出

5、重启mysql
           service mysqld restart    #重启mysql,这个时候mysql的root密码已经修改为123456

6、进入mysql控制台
           mysql -uroot -p  #进入mysql控制台
           123456 #输入密码

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广