Linux下安装、启动MySQL

 三四年没有安装过mysql+apache+PHP的环境了,我以前是做银行性能测试外包服务的,在甲方开发中心遇到这样环境的项目也比较少,大多是WebLogic/WebSphere+Oracle/DB2架构的大型系统。涉足电商行业方面的项目,不得不再去温故那些几乎遗忘的IIS、apache、MSsql、mysql等环境。

平台:VMware上虚拟的centos4.7

宿主机:windows

安装mysql前准备:

1、检查该环境中是否已安装mysql,检查方法:netstat –ano命令查看mysql默认端口3306是否存在;或者再命令行中执行mysql

2、下载mysql安装包

http://www.mysql.com/downloads/mysql/#downloads下载mysql安装包:

MySQL-server-5.5.28-1.linux2.6.i386.rpm

MySQL-client-5.5.28-1.linux2.6.i386.rpm

使用rpm –ivh命令来安装mysql,这里不说啦。

先来了解一下mysql数据库默认的一些主要目录:

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

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

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

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

安装后通过netstat –ano命令查看mysql默认端口3306是否存在,如果不存在,按下面的方法启动mysql服务。

启动mysql服务:

 

[html]  view plain copy
 
  1. [root@localhostmysql]# pwd  
  2. /usr/share/mysql  
  3. [root@localhostmysql]# ./mysql.server start  
  4. StartingMySQL...[  确定  ]  
  5. [root@localhostmysql]# netstat -ano  
  6. ActiveInternet connections (servers and established)  
  7. ProtoRecv-Q Send-Q Local Address              Foreign Address            State       Timer  
  8. tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      off (0.00/0/0)  
  9. [root@localhostmysql]# mysql  
  10. Welcometo the MySQL monitor.  Commands end with; or \g.  
  11. YourMySQL connection id is 1  
  12. Serverversion: 5.5.28 MySQL Community Server (GPL)  
  13. Copyright(c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.  
  14. Oracle isa registered trademark of Oracle Corporation and/or its  
  15. affiliates.Other names may be trademarks of their respective  
  16. owners.  
  17. Type'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  18. mysql>  
  19. mysql>  

启动与停止

1、启动
  MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。  

[html]  view plain copy
 
  1. [root@localhost mysql]#  /etc/init.d/mysql start  

 

2、停止  

[html]  view plain copy
 
  1. [root@localhost mysql] #  /usr/bin/mysqladmin -u root -p shutdown  

 

3、自动启动
  1)察看mysql是否在自动启动列表中  

[html]  view plain copy
 
  1. [root@localhost mysql] # /sbin/chkconfig –list  

 

  2)把MySQL添加到你系统的启动服务组里面去  

[html]  view plain copy
 
  1. [root@localhost mysql] # /sbin/chkconfig – add mysql  

 

  3)把MySQL从启动服务组里面删除。 

[html]  view plain copy
 
  1. [root@localhost mysql] # /sbin/chkconfig – del mysql  

猜你喜欢

转载自dbajun.iteye.com/blog/2185369