1.查找已经安装的文件
[root@localhost ~]# rpm -qa | grep -i mysql mysql-libs-5.1.66-2.el6_3.x86_64
2.删除
#rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64
3.安装RPM文件
#rpm -ivh MySQL-server-xxx.el6.x86_64.rpm #rpm -ivh MySQL-client-xxx-1.el6.x86_64.rpm #rpm -ivh MySQL-devel-xxx-1.el6.x86_64.rpm
4.修改配置文件位置
# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
5.初使化MYSQL及配置密码
# /usr/bin/mysql_install_db # service mysql start # cat /root/.mysql_secret #查看root账号密码 # The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl # mysql -uroot –pqKTaFZnl mysql> SET PASSWORD = PASSWORD('123456'); #设置密码为123456 mysql> exit # mysql -uroot -p123456
6.设置允许远程登录
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 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | localhost.localdomain | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 | | 127.0.0.1 | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 | | ::1 | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 | +-----------------------+------+-------------------------------------------+ 4 rows in set (0.00 sec) mysql> update user set password=password('root') where user='root'; Query OK, 3 rows affected (0.01 sec) Rows matched: 4 Changed: 3 Warnings: 0 mysql> update user set host='%' where user='root' and host='localhost'; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
7.设置开机自启动
# chkconfig mysql on # chkconfig --list | grep mysql mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
8.配置字符集
配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.
[client] password = 123456 port = 3306 default-character-set=utf8 [mysqld] port = 3306 character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci #(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写) lower_case_table_names=1 #(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; ) max_connections=1000 [mysql] default-character-set = utf8
9.查看字符集
show variables like '%collation%';show variables like '%char%';