基础介绍:
1.在linux下使用下列命令,请确认mysql的bin目录是否已经加入到PATH路径中,或者是已经进入到mysql安装路径下的bin目录
查看PATH
shell> echo $PATH

或者
shell> cd /usr/local/mysql/bin

2.windows下,请运行cmd后,同样检查mysql的bin目录是否已加入到系统的PATH路径中,或直接进入mysql的安装目录

下面所有操作都是确认你以检查mysql的bin目录已加入到系统的PATH路径中,或已经进入mysql的安装目录的bin目录下

1]如何创建mysqld数据库的管理用户?

数据库安装好后,我们应该为mysql数据库创建一个管理帐号。要把root用户设置为管理员,我们应该运行下面的命令;
shell> mysqladmin -u root password 123456

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

2]如何进入mysql数据库?以mysql数据库管理员root,密码为123456为例;
shell> mysql -uroot -p123456[code]
输出上面的命令后,出现的是如下的提示;
[code]Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 6 to server version: 3.23.58

Type 'help;' or '/h' for help. Type '/c' to clear the buffer.

mysql>

注意:操作这些命令的时候,应该把mysqld服务器打开。这些新手兄弟早就知道了吧:)

3]如何在数据库中操作命令呢,我想这是mysql手册都有的,我主要说几个要注意的地方。其实我也会不了几个命令。如果自己想学的弟兄,也不是什么难事;在windows中操作过mysql的,其实在这里也是一样的,mysql是跨平台的数据库,用法都是相同的。

在mysql数据库中,每操作一个命令,都是;号结尾的,可能有的新手弟兄,忘记输入了;号结尾,结果退不出来。:):)

1]查看mysql中都有哪些数据库?

代码:
mysql>
show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec) mysql>

在mysql安装好,设置好管理员后,第一次进入系统,我们用show databases;命令查看数据库的列表,发现有两个数据库,mysql和test,这是系统自建的,是让大家练习用的。

4]如何创建和删除一个数据库?

比如我要创建一个名为linux的数据库,应该运行如下命令
mysql> create database [数据库名];

所以我们应该运行如下的命令,来创建名为linux的数据库
mysql> create database linux;
Query OK, 1 row affected (0.00 sec)

是不是建好了呢??肯定是建好了,因为都有OK了:)

查看是不是有linux这个数据库了呢?

代码:
mysql> show databases;
+----------+
| Database |
+----------+
| linux |
| mysql |
| test |
+----------+
3 rows in set (0.00 sec)

那我们如何删除一个数据库呢??
mysql> drop database [数据库名];

比如我们要把刚才创建的linux数据库删除,应该用下面的命令;
mysql> drop database linux;
Query OK, 0 rows affected (0.00 sec)

是不是已经删除了呢??

代码:
mysql> show databases;
+----------+
| Database |
+----------+
| mysql |
| test |
+----------+
2 rows in set (0.00 sec)

5]如何操作一个数据库呢,这个问题就比较多了,建议还是看一下mysql的手册吧。里面的东西太多了。如果操作一个数据库,首先是要指定一个数据库为当前数据库,应该用use命令

mysql>use [数据库];

比如我想指定linux这个数据库为当前数据库,应该是
mysql> use linux;
Database changed

6]如何备份数据库??

比如我们要备份mysql中已经存在的名为linux的数据库,要用到命令mysqldump

命令格式如下:
shell> mysqldump -uroot -p linux > /root/linux.sql
Enter password:在这里输入数据库的密码

通过上面的命令,我们要明白两件事,首先备份数据库是要以数据库管理员的身份备份;其次:备份目的地是/root,备份的文件名是linux.sql。其实备份的位置和文件名,根据自己的情况来定。文件名可以自己来取,路径也可以自己来安排;

比如我想把linux的数据库备份到/home/beinan,数据库的文件名为linuxsir031130.sql,所以应该输入如下的命令。
shell> mysqldump -uroot -p linux > /home/beinan/linuxsir031130.sql
Enter password:在这里输入数据库管理员root的数据库密码

这样我们到/home/beinan目录下就能发现mysql中名为linux的数据库的备份文件linuxsir031130.sql

综上所述,我们学习时要学会变通。:):)

5]如何把把备份的数据库导入到数据库中?

首先我们还是要操作上面几个过程,比如添加数据库管理员(如果您没有添加过mysql数据库管理员的话),创建数据库等。

比如我们要把在/home/beinan这个目录中的linuxsir031130.sql这个备份,导入名为linux的数据库中,应该如下操作;
shell> mysql -uroot -p linux < /home/beinan/linuxsir031130.sql
Enter password:在这里输入密码

如果机器好,数据库比较小,几分钟就好了。

6]其它一些比较常用的mysql指令;

查看状态
mysql> show status;

查看进程
代码:
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+| 16 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+
1 row in set (0.00 sec)

查看表,应该先指定一个数据库为当前数据库;比如是名为linux的数据库;
mysql>use linux;
mysql> show tables;
Empty set (0.00 sec)

7]对mysql数据库常用命令的一点补充;

几个常用的mysql相关的管理命令

mysql 命令:基本文本的,显示和使用的mysql数据库。前面已经简单的提过用法;比如登录等。

mysqladmin 命令,用来创建和维护mysql数据库的命令,前面已经简单的提过;

isamchk 是用来修复、检查和优化.ism后缀的数据库文件;

mysqldump 是用于备份数据库,前面已经简单的说明过;

myisamchk 用来修复.myi后缀的数据库文件;

比如我们要检查名为linux的数据库.myi数据库表是否存在问题,应该用下面的命令;

要把mysqld服务器停下来
shell> ../share/mysql.server stop

然后执行
shell> myisamchk ../var/linux/*.MYI

上面的命令的意思就是检查所有的.myi文件,数据库的目录在../var/linux/目录中

如果有问题,应该用-r参数来修复
shell> myisamchk -r ../var/linux/*.MYI

6]mysqlshow 命令:显示用户选择的数据库和表
shell> mysqlshow -uroot -p [数据库名]

比如我要查看名为linux的数据库;应该是:
[cdoe]shell> mysqlshow -uroot -p linux[/code]
好了,到这里,你可能已经知道命令行下的所有基本操作了~

ps:补充一个。。
更改ROOT帐号名。
update set user="新名字" where user="旧名字";
Web Server | 评论(10) | 引用(0) | 阅读(1030)
Replica Handbags Email Homepage
2012/05/18 16:21
This is really my very first time here, great looking blog.
UGG for men Email Homepage
2011/12/02 14:58
sadsa Email Homepage
2011/11/30 12:31
Someone essentially help to create seriously posts I would state. This is the extremely first time I frequented your web site page and thus far? I amazed with the analysis you made to create this particular publish amazing. Great job!
virtual receptionist
sadsa Email Homepage
2011/11/30 12:28
I’m trying to find out what the most popular blogs are when it comes to news and views and cell phone stuff..
<a href="http://www.csnotepad.co.uk/">virtual receptionist</a>
uggs slippers Email Homepage
2011/10/27 20:37
We’ve continuously heard been recently looking close to within your web-site proper just after I observed about these from a shut buddy and was delighted when I was in a very placement to obtain it following seeking out for some time. Being a passionate blogger, I’m pleased to see other individuals taking effort and including to the neigh
orhood.
uggs discount Email Homepage
2011/10/14 14:40
resume writing Email Homepage
2011/06/30 14:56
我不明白为什么你喜欢的Linux!他只有把自动柜员机上,因为它难以破解
meche Email
2011/06/11 16:03
It really is actually a revolution in running enthusiast. Following adapt the sport technique of general running, it is tough for them to test for vibram five fingers sprint, which looks like odd and strange.
dsatew Email Homepage
2011/04/22 11:59
Way back in 1970, people would carry into account wearing an pricey watch a standing insignia. Not any more unless you are talking about a designer collections.
dsatew Email Homepage
2011/04/22 11:59
Employing its amazing burden and therefore excellent products, excellent sewing in addition to an individual's total degree of burden and therefore turning into one of the best on the market, Nike shall be uncertainness your plant that is certainly in this article to stay.
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]