(说明:安装完client后直接执行不行,告诉我们不能连接到MySQL server,要求检查mysqld是否在运行并且socket文件'/var/lib/mysql/mysql.sock'是否存在
1. 查看mysql默认端口号3306是否被占用
1.1 netstat –an命令查看mysql默认端口3306的情况,没有查找到
[root@localhost bin]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:878 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.10.249:56602 192.168.10.247:445 ESTABLISHED
tcp 0 0 :::22 :::* LISTEN
udp 0 0 0.0.0.0:40386 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp 0 0 0.0.0.0:872 0.0.0.0:*
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:875 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:631 0.0.0.0:*
udp 0 0 :::43145 :::*
udp 0 0 :::5353 :::*
Active UNIX domain sockets (servers and established)
1.2 用netstat -pan|grep 3306查看短款的情况也可以
[root@localhost bin]# netstat -pan|grep 3306 #查询结果为空
[root@localhost bin]#
2. 紧接着进入/var/lib/mysql下面查看”mysql.sock”文件是否存在,不存在
3. [root@localhost /]# /etc/rc.d/init.d/mysql status
MySQL is not running [FAILED]
通过上面的几种检查结果可以初步断定mysql服务还没有启动,那先启动mysql服务吧
)
1.启动mysql服务
启动mysql的方式有很多
1. MySQL安装完成后启动文件mysql在/etc/init.d目录下,在需要启动时运行下面命令即可。
[root@localhost]# /etc/init.d/mysql start
2. 停止服务
[root@localhost]# /usr/bin/mysqladmin -u root -p shutdown
3. 开机自启动
一般情况下mysql安装完成后会被注册为系统服务,可以通过/sbin/chkconfig –list命令检查mysql是否被注册为系统服务
[root@localhost /]# /sbin/chkconfig --list
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
如果已经注册则执行service mysql start启动服务,停止则service mysql stop
[root@localhost sbin]# service mysql start
Starting MySQL. [ OK ]
如果没有注册则执行将mysql加入到系统的启动服务组里面去
[root@localhost sbin]# /sbin/chkconfig -- add mysql
把MySQL从启动服务组里面删除
[root@localhost sbin]# /sbin/chkconfig --del mysql
4. 继续上面的操作,修改mysql的root用户的密码
[root@localhost bin]# mysqladmin -uroot password "manager" 成功
5. 重新进入/var/lib/mysql/查看mysql.sock文件存在了
[root@localhost mysql]# ls /var/lib/mysql
ibdata1 ib_logfile1 localhost.localdomain.pid mysql.sock RPM_UPGRADE_HISTORY test
ib_logfile0 localhost.localdomain.err mysql performance_schema RPM_UPGRADE_MARKER-LAST
[root@localhost mysql]#
2.进入mysql数据库
[root@localhost bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.8 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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 |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
3.优化mysql,更改mysql目录
MySQL默认的数据文件存储目录为/var/lib/mysql。假如要把目录移到/home/mysql_data目录需要如下操作:
1. 创建mysql_data目录
[root@localhost mysql]# mkdir /home/mysql_data
[root@localhost mysql]# cd /home
[root@localhost home]# ls
lost+found mysql mysql_data sunny
2. 未保证mysql所有文件正常且不被损坏或占用,在调整目录前需要停止mysql服务或者杀掉mysql进程
[root@localhost home]# /usr/bin/mysqladmin -u root -p shutdown(杀掉mysql进程)
Enter password:
[root@localhost home]#service mysql stop (停止mysql服务)
3. 把/var/lib/mysql整个目录移到/home/data
[root@localhost home]# mv /var/lib/mysql/ /home/mysql_data/
[root@localhost home]#
4. 修改配置文件my.cnf
配置文件一般都在/etc目录下,如果/etc/目录下没有my.cnf配置文件,则需要到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个(比如:my-medium.cnf)到/etc/目录下,并重命名为my.cnf
[root@localhost home]# ls /usr/share/mysql/*.cnf
/usr/share/mysql/my-huge.cnf /usr/share/mysql/my-large.cnf /usr/share/mysql/my-small.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf /usr/share/mysql/my-medium.cnf
[root@localhost home]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
[root@localhost home]# find /etc/my.cnf
/etc/my.cnf
[root@localhost home]#
为保证mysql能够正常工作,需要编辑my.conf,调整mysql.sock文件的指向位置
[client]
#password = your_password
port = 3306
#socket = /var/lib/mysql/mysql.sock
socket = /home/mysql_data/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock
socket = /home/mysql_data/mysql/mysql.sock
skip-external-locking
<P class=MsoListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l3 level1 lfo4; ms