日期:2014-05-16  浏览次数:20766 次

MySQL 指令、語法及管理
如果以前安装了,卸载以前的版本
#rpm -e --nodeps mysql-3.23.58-2.3
服务端安装:
#rpm -ivh MySQL-server-5.0.9-0.i386.rpm
显示如下:
warning: MySQL-server-5.0.9-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
050718 16:12:26 [Warning] Asked for 196608 thread stack, but got 126976
050718 16:12:26 [Warning] Asked for 196608 thread stack, but got 126976
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
See the manual for more instructions.
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at https://order.mysql.com
Starting MySQL.. SUCCESS!
运行命令:
#netstat -nat
显示:
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN
客户端安装:
#rpm -ivh MySQL-client-5.0.9-0.i386.rpm
显示如下:
warning: MySQL-client-5.0.9-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
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的目录)
启动与停止
  1、启动
  MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。
  [root@test1 init.d]# /etc/init.d/mysql start
  2、停止
  /usr/bin/mysqladmin -u root -p shutdown
  3、自动启动
  1)察看mysql是否在自动启动列表中
  [root@test1 local]# /sbin/chkconfig --list
  2)把MySQL添加到你系统的启动服务组里面去
  [root@test1 local]# /sbin/chkconfig --add mysql
  3)把MySQL从启动服务组里面删除。
  [root@test1 local]# /sbin/chkconfig --del mysql
修改登录密码
  MySQL默认没有密码,安装完毕增加密码的重要性是不言而喻的。
  1、命令
  usr/bin/mysqladmin -u root password 'new-password'
  格式:mysqladmin -u用户名 -p旧密码 password 新密码
  2、例子
  例1:给root加个密码123456。
  键入以下命令 :
  [root@test1 local]# /usr/bin/mysqladmin -u root password 123456
  注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
  3、测试是否修改成功
   1)不用密码登录
  [root@test1 local]# mysql
  ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
  显示错误,说明密码已经修改。
  2)用修改后的密码登录
  [root@test1 local]# mysql -u root -p
  Enter password: (输入修改后的密码123456)
  Welcome to the MySQL monitor. Commands end with ; or \g.
  Your MySQL connection id is 4 to server version: 4.0.16-standard
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql>
  成功!
  这是通过mysqladmin命令修改口令,也可通过修改库来更改口令。

更改MySQL目录
  MySQL默认的数据文件存储目录为/var/lib/mysql。假如要把目录移到/home/data下需要进行下面几步:
  1、home目录下建立data目录
  cd /home
  mkdir data
  2、把MySQL服务进程停掉:
  mysqladmin -u root -p shutdown
  3、把/var/lib/mysql整个目录移到/home/data