Centos 6.2 安装Mysql笔记

来源:互联网 发布:尼康d800调焦软件 编辑:程序博客网 时间:2024/05/29 18:16

1、安装命令

# yum install mysql-server mysql


2、查看是否安装正确

# chkconfig --list mysqld

 

3、启动
 (1)、启动服务:

# service mysqld start

 

 (2)、停止服务: 

# mysqladmin -u root -p shutdown

 

 (3)、加入开机启动:

# chkconfig mysqld on

 
 (4)、移除开机启:  

 # chkconfig mysqld off

 

 (5)、查看服务是否正在运行:

 第一种方法:

service --status-all | grep mysqld

 第二种方法:

service mysqld status

 

4、进入
 (1)、第一次进入时,因为Root用户密码为空,输入:

# mysql   


 (2)、设置Mysql root用户密码:

 # mysqladmin -u root password '123456'

 

 (3)、有密码时进入Mysql:

# mysql -u root -p 


5、更改MySQL数据库目录

    MySQL默认的数据文件存储目录为/var/lib/mysql。 假如要把目录移到/home/data

(1)、找到my.cnf配置文件
  如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf)中。
 命令如下: 

# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf


 (2)、编辑MySQL的配置文件/etc/my.cnf 
     修改socket=/var/lib/mysql/mysql.sock一行中等号右边的值为:/home/mysql/mysql.sock

复制代码
vi  my.cnf //(用vi工具编辑my.cnf文件,找到下列数据修改之)      //(原内容,为了更稳妥用“#”注释此行)      #datadir=/var/lib/mysql     datadir=/home/data/mysql     #socket=/var/lib/mysql/mysql.sock     socket=/home/data/mysql/mysql.sock
复制代码

 

(3)、修改MySQL启动脚本/etc/rc.d/init.d/mysqld
   

 # vi /etc/rc.d/init.d/mysqld    #datadir=/var/lib/mysql    (注释此行)  datadir=/home/data/mysql   (加上此行)

   
   重新启动MySQL服务 services   mysql restart  或用reboot命令重启Linux

 


注、如果出现如下错误:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
解决办法:

方法: 修改/etc/my.cnf:

复制代码
[mysqld] datadir=/home/data/mysqlsocket=/home/data/mysql/mysql.sock[mysql.server] user=mysql datadir=/home/data If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as: [client] socket=/home/data/mysql/mysql.sock
复制代码

 


如果你想连接你的mysql的时候发生这个错误:

ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server


解决方法:可以参数 Linux下MySQL数据库常用操作一中的授权操作http://www.cnblogs.com/xdpxyxy/archive/2012/11/16/2773662.html

 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

复制代码
#mysql -u root -p //登录mysql>use mysql;//必须先设置root密码,再删除User表中password为空的其它记录mysql>delete from user where password='';//修改user表里的 "host" 项,从"localhost"改称"%"mysql>update user set host = '%' where user = 'root'; mysql> select host,user,password from user;+------+------+-------------------------------------------+| host | user | password                                  |+------+------+-------------------------------------------+| %    | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+------+------+-------------------------------------------+1 row in set (0.00 sec)
复制代码


/etc/my.cnf:MySQL服务器配置文件。

/var/lib/mysql:MySQL数据目录,可以通过my.cnf修改。

/usr/bin/mysqlamdin:MySQL服务器命令行程序。

/usr/bin/mysql:MySQL客户端命令行程序。

 


检查服务状态:

service --status-all

service --status-all | grep ntpd

service --status-all | less

service httpd status

列出所有服务启动级别:

chkconfig --list

列出服务和他们对应的端口:

netstat -tulpn

原创粉丝点击