Linux下安装Mysql,使用yum来安装,方便简单,按步骤操作就可以了。但是在启动时报“[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist”,下面给出自己的解决办法。

 环境和软件:CentOS5.6、Mysql5.1

Mysql安装

首先,查看是否已经安装mysql 如果已经安装了mysql 按步骤删除

[root@hadoop001 ~]# yum list installed | grep mysql                      
[root@hadoop001 ~]# rpm -qa | grep mysql*
[root@hadoop001 ~]# yum remove mysql mysql-server mysql-libs compat-mysql51 -y

查看/var/lib/mysql文件和/etc/my.cnf  如果存在的话,删除

[root@hadoop001 ~]# rm -rf /var/lib/mysql
[root@hadoop001 ~]# rm /etc/my.cnf

查看是否已经删除mysql安装 如有存在的话 继续上一步删除

[root@hadoop001 ~]# yum list installed | grep mysql*
[root@hadoop001 ~]# rpm -qa | grep mysql*

查看yum中是否存在mysql-server和mysql-devel安装包

[root@hadoop001 ~]# yum list mysql*

存在的话 直接安装,先安装mysql客户端,在安装mysql服务端

[root@hadoop001 ~]# yum install mysql -y
[root@hadoop001 ~]# yum install mysql-server mysql-devel -y
Installed:
 mysql-devel.x86_64 0:5.1.71-1.el6 mysql-server.x86_64 0:5.1.71-1.el6 

Dependency Installed:
 keyutils-libs-devel.x86_64 0:1.4-4.el6 krb5-devel.x86_64 0:1.10.3-10.el6_4.6 libcom_err-devel.x86_64 0:1.41.12-18.el6 
 libselinux-devel.x86_64 0:2.0.94-5.3.el6_4.1 libsepol-devel.x86_64 0:2.0.41-4.el6 openssl-devel.x86_64 0:1.0.1e-15.el6 
 perl-DBD-MySQL.x86_64 0:4.013-3.el6 perl-DBI.x86_64 0:1.609-4.el6 zlib-devel.x86_64 0:1.2.3-29.el6 

Complete!

如果出现上面的的提示,则说明mysql已经安装成功了,下面进行mysql的配置和用户的添加。

配置

配置mysql编码格式和忽略对字母大小写敏感

[root@hadoop001 ~]# vim /etc/my.cnf
添加如下信息在mysqld中,
 #设置字符集编码格式
 character-set-server=utf8
 #忽略表英文字母大小写
 lower_case_table_names=1

查看mysql状态,启动mysql服务,并设置为开机启动项

[root@hadoop001 ~]# service mysqld status
[root@hadoop001 ~]# service mysqld start
[root@hadoop001 ~]# chkconfig mysqld on

添加用户

第一次登录mysql数据,不需要输入密码,我们可以直接使用root登录到mysql中,并对表进行操作,添加用户和对mysql的访问权限信息等操作。可以通过改表(sql语句操作)和授权两种方式,添加用户和设置用户访问权限。

[root@hadoop001 ~]# mysql -uroot
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user,password from user;
+-----------+------+----------+
| host | user | password |
+-----------+------+----------+
| localhost | root | |
| hadoop001 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| hadoop001 | | |
+-----------+------+----------+
5 rows in set (0.00 sec)
  • 改表法
mysql> update user set password=password("123456") where user="root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> update user set host = '%' where user = 'root' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0

mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| % | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| hadoop001 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | | |
| hadoop001 | | |
+-----------+------+-------------------------------------------+
5 rows in set (0.00 sec)
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

 博文转自于:http://www.itzoo.net/db/729.html

 

Logo

更多推荐