您的位置:首页 > 数据库 > MySQL

ubuntu 下mysql使用方法简介及mysql密码丢失的修复

2009-10-17 13:49 441 查看

ubuntu 下mysql使用方法简介

参考
http://hi.baidu.com/fancx/blog/item/4b91d82a5c66582bd42af1ca.html
http://hi.baidu.com/cnlen/blog/item/eb1251661646c820aa184c20.html
 
 

一、密码丢失的修复

l        停止MYSQL服务器:

$sudo /etc/init.d/mysql stop

收到打印信息

* Stopping MySQL database server mysqld                            [ OK ]

l        跳过授权表执行MYSQL服务器:

$sudo mysqld_safe --skip-grant-tables --skip-networking &

(注:参数--skip-grant-tables为跳过授权表;--skip-networking为不监听TCP/IP连接)
收到打印信息

[1] 8292 nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[8334]: started

l        执行MYSQL客户端:

$mysql

收到打印信息

Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 1
Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)
 
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
 
mysql>

l        使用mysql数据库

mysql>use mysql;

收到打印信息

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

l        更新root密码

mysql>update user set password='' where user='root';

这里是加一个空密码给root;
收到打印信息

Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

l        退出mysql数据库

mysql> exit

收到打印信息

Bye

l        重新启动mysql服务器

$sudo /etc/init.d/mysql start

l        重新设置密码

$sudo /use/bin/mysqladmin -u root password 123456

通过上面的命令,我们可以知道,mysql数据库的管理员是root,密码是123456。

二,mysql基本操作

进入mysql数据库

$mysql -uroot -p123456

常用命令

mysql>create database db1;   #创建数据库;  
mysql>show databases;                         #查看系统中数据库;  
mysql>use db1;                                     #指定要操作的数据库名称;  
mysql>create tables tab1;                      #在db1数据库中创建表tab1;  
mysql>show tables;                               #查看db1数据库包含的数有数据表;  
mysql>drop database db1;                    #删除数据库db1;  
mysql>drop table tab1;                          #删除db1数据库中的表tab1;  
mysql>desc tab1;                                  #查看tab1表的结构;  
mysql>select * from tabl;                       #查看表tab1的所有项;  

 
 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息