RPM方式安装MySQL
a. 检查mysql及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)
[root@localhost ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.66-2.el6_3.x86_64
[root@localhost ~]# yum -y remove mysql-libs*
b. 下载Linux对应的RPM包,如:CentOS对应的RPM包,如下:
//devel:
wget http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-devel-6.1.6-1.linux_glibc2.5.i386.rpm
//client:
wget ftp://ftp.icm.edu.pl/vol/rzm4/mysql/Downloads/MySQL-5.6/MySQL-client-5.6.25-1.linux_glibc2.5.i386.rpm
//server:
wget ftp://ftp.icm.edu.pl/vol/rzm4/mysql/Downloads/MySQL-5.6/MySQL-server-5.6.26-1.linux_glibc2.5.i386.rpm
或者打开网页下载,移动到所需目录
http://rpm.pbone.net/index.php3/stat/4/idpl/30709898/dir/other/com/MySQL-server-5.6.26-1.linux_glibc2.5.i386.rpm.html
http://rpm.pbone.net/index.php3/stat/4/idpl/29482009/dir/other/com/MySQL-client-5.6.25-1.linux_glibc2.5.i386.rpm.html
http://dev.mysql.com/downloads/file/?id=456205
[root@localhost ~]# ll
total 112544
-rw-rw-r--. 1 footmart footmart 22935183 Aug 12 20:38 MySQL-client-5.6.25-1.linux_glibc2.5.i386.rpm
-rw-rw-r--. 1 footmart footmart 4056228 Aug 12 17:50 mysql-connector-c-devel-6.1.6-1.linux_glibc2.5.i386.rpm
-rw-rw-r--. 1 footmart footmart 88246330 Aug 12 20:56 MySQL-server-5.6.26-1.linux_glibc2.5.i386.rpm
c.安装Mysql
[root@localhost Public]# rpm -ivh MySQL-client-5.6.25-1.linux_glibc2.5.i386.rpm
[root@localhost Public]# rpm -ivh MySQL-server-5.6.26-1.linux_glibc2.5.i386.rpm
[root@localhost Public]# rpm -ivh mysql-connector-c-devel-6.1.6-1.linux_glibc2.5.i386.rpm
[root@localhost Public]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
[root@localhost ~]# /usr/bin/mysql_install_db #修改配置文件位置
[root@localhost ~]# service mysql start
d. 初始化 MySQL 及设置密码
[root@localhost rpm]# cat /root/.mysql_secret #查看root账号密码
# The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): Zg4fm34MvI2OaPGv
[root@localhost ~]# mysql -uroot –Zg4fm34MvI2OaPGv
mysql> SET PASSWORD = PASSWORD('123'); #设置密码为123
mysql> exit
[root@localhost ~]# mysql -uroot -p123
e. 允许远程登陆
mysql> use mysql;
mysql> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host | user | password |
+-----------------------+------+-------------------------------------------+
| localhost | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| localhost.localdomain | root | *9180C7B178A84F847DF7F5F61F34AF056103144E |
| 127.0.0.1 | root | *9180C7B178A84F847DF7F5F61F34AF056103144E |
| ::1 | root | *9180C7B178A84F847DF7F5F61F34AF056103144E |
+-----------------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> update user set password=password('123') where user='root';
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit
f. 设置开机自启动
[root@localhost ~]# chkconfig mysql on
[root@localhost ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
g. MySQL的默认安装位置
/var/lib/mysql/ #数据库目录
/usr/share/mysql #配置文件目录
/usr/bin #相关命令目录
/etc/init.d/mysql #启动脚本
修改字符集和数据存储路径
配置/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
查看字符集
show variables like '%collation%';
show variables like '%char%';