下载地址:
http://cdn.MySQL.com/archives/mysql-5.6/MySQL-server-5.6.13-1.el6.x86_64.rpm
http://cdn.mysql.com/archives/mysql-5.6/MySQL-devel-5.6.13-1.el6.x86_64.rpm
http://cdn.mysql.com/archives/mysql-5.6/MySQL-client-5.6.13-1.el6.x86_64.rpm
在RedHat 6.3下安装MySQL-server-5.6.13-1.el6.x86_64.rpm
首先下载下面三个文件:
MySQL-client-5.6.13-1.el6.x86_64.rpm
MySQL-devel-5.6.13-1.el6.x86_64.rpm
MySQL-server-5.6.13-1.el6.x86_64.rpm
然后使用root账号登陆,进行安装:
1. 安装server、devel、client:1. 安装server、devel、client:
rpm -ivh --replacefiles MySQL-s*.rpm
rpm -ivh --replacefiles MySQL-d*.rpm
rpm -ivh --replacefiles MySQL-c*.rpm
发现缺libaio.so包
error: Failed dependencies:
/usr/bin/perl is needed by MySQL-server-5.6.22-1.el6.x86_64
libaio.so.1()(64bit) is needed by MySQL-server-5.6.22-1.el6.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.22-1.el6.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.22-1.el6.x86_64
error: Failed dependencies:
/usr/bin/perl is needed by MySQL-server-5.6.22-1.el6.x86_64
解决方法
[root@xcldtc5m mysql]# yum install libaio
[root@xcldtc5m mysql]# yum install perl
[root@localhost download]# rpm -ivh --replacefiles MySQL-server-5.6.13-1.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]
[root@localhost download]# rpm -ivh --replacefiles MySQL-client-5.6.13-1.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]
[root@localhost download]# rpm -ivh --replacefiles MySQL-devel-5.6.13-1.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-devel ########################################### [100%]
要移除安装可以使用 rpm -e MySQL-server 、 rpm -e MySQL-devel、MySQL-client即可;
2. 初始化数据库:
/usr/bin/mysql_install_db
3. 启动mysql服务:
service mysql start
使用命令ps -ef | grep mysql 查看mysql进程:
[root@localhost ~]# ps -ef | grep mysql
root 26047 1 0 18:14 pts/12 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
mysql 26227 26047 0 18:14 pts/12 00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock
root 26545 24726 0 18:27 pts/8 00:00:00 grep mysql
4.第一次登陆设置root密码:
首先查看 cat /root/.mysql_secret
root@localhost ~]# cat /root/.mysql_secret
# The random password set for the root user at Fri Aug 30 15:57:18 2013 (local time): fMYcarvB
然后命令行:mysql -u root -p ,然后输入上面的密码即可:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5
Server version: 5.6.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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.
设置root密码:
SET PASSWORD=password('123456');
退出,重新登陆即可使用新的密码登陆;
5. 设置远程登陆:
使用root登陆到mysql后
mysql> update user set host='%' where user='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
mysql> select host,user from user;
+-----------------------+------+
| host | user |
+-----------------------+------+
| % | root |
| 127.0.0.1 | root |
| 192.168.128.142 | root |
| ::1 | root |
| localhost.localdomain | root |
+-----------------------+------+
5 rows in set (0.00 sec)
然后:
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.08 sec)
mysql> exit
Bye
[root@localhost ~]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
重启mysql即可远程登陆。
如果远程还是无法连接,请检查防火墙是否开启
/etc/init.d/iptables status
如果开启 请关闭
/etc/init.d/iptables stop
###########################################################
RPM方式安装MySQL5.6
a. 检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)
1 |
[root@localhost ~] # rpm -qa | grep -i mysql |
2 |
mysql-libs-5.1.66-2.el6_3.x86_64 |
3 |
[root@localhost ~] # yum -y remove mysql-libs* |
b. 下载Linux对应的RPM包,如:CentOS6.4_64对应的RPM包,如下:
1 |
[root@localhost rpm] # ll |
2 |
total 74364 |
3 |
-rw-r--r--. 1 root root 18442536 Dec 11 20:19 MySQL-client-5.6.15-1.el6.x86_64.rpm |
4 |
-rw-r--r--. 1 root root 3340660 Dec 11 20:06 MySQL-devel-5.6.15-1.el6.x86_64.rpm |
5 |
-rw-r--r--. 1 root root 54360600 Dec 11 20:03 MySQL-server-5.6.15-1.el6.x86_64.rpm |
c. 安装MySQL
1 |
[root@localhost rpm] # rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm |
2 |
[root@localhost rpm] # rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm |
3 |
[root@localhost rpm] # rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm |
4 |
#修改配置文件位置 |
5 |
[root@localhost rpm] # cp /usr/share/mysql/my-default.cnf /etc/my.cnf |
d. 初始化MySQL及设置密码
1 |
[root@localhost rpm] # /usr/bin/mysql_install_db |
2 |
[root@localhost rpm] # service mysql start |
3 |
[root@localhost rpm] # cat /root/.mysql_secret #查看root账号密码 |
4 |
# The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl |
5 |
[root@localhost ~] # mysql -uroot –pqKTaFZnl |
6 |
mysql> SET PASSWORD = PASSWORD( '123456' ); #设置密码为123456 |
7 |
mysql> exit |
8 |
[root@localhost ~] # mysql -uroot -p123456 |
e. 允许远程登陆
01 |
mysql> use mysql; |
02 |
mysql> select host,user,password from user; |
03 |
+-----------------------+------+-------------------------------------------+ |
04 |
| host | user | password | |
05 |
+-----------------------+------+-------------------------------------------+ |
06 |
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | |
07 |
| localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 | |
08 |
| 127.0.0.1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 | |
09 |
| ::1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 | |
10 |
+-----------------------+------+-------------------------------------------+ |
11 |
12 |
mysql> update user set password=password( '123456' ) where user= 'root' ; |
13 |
mysql> update user set host= '%' where user= 'root' and host= 'localhost' ; |
14 |
mysql> flush privileges; |
15 |
mysql> exit |
f. 设置开机自启动
1 |
[root@localhost ~] # chkconfig mysql on |
2 |
[root@localhost ~] # chkconfig --list | grep mysql |
3 |
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
g. MySQL的默认安装位置
1 |
/var/lib/mysql/ #数据库目录 |
2 |
/usr/share/mysql #配置文件目录 |
3 |
/usr/bin #相关命令目录 |
4 |
/etc/init.d/mysql #启动脚本 |
修改字符集和数据存储路径
配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.
- [client]
- password = 123456
- port = 3306
- default-character-set=utf8
- [mysqld]
- log-error=/usr/mysql.log #启动错误日志,没设置的话默认在 /usr/mysql.log
- 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%';
###########################################################
windows下安装mysql解压版
在windows下安装mysql解压版很简单,分分钟的事情,但是要使用好mysql,还是要多加以练习才行。下面说下安装步骤。
1、到官网下载最新的mysql版本,并解压到任意路径,比如:D:Program Filesmysqlmysql-5.6.11-win32
2、设置环境变量:新建变量名:MYSQL_HOME,值为你解压的路径:D:Program Filesmysqlmysql-5.6.11-win32
3、然后在系统变量path中添加:“;%MYSQL_HOME%in“,
4、打开mysql根目录,会发现有my-default.ini文件,复制然后重命名为my.ini
5、在my.ini中添加如下内容:
[mysqld]
#设置字符集为utf8
loose-default-character-set = utf8
basedir = D:/Program Files/mysql/mysql-5.6.11-win32
datadir = D:/Program Files/mysql/mysql-5.6.11-win32/data
[client]
loose-default-character-set = utf8
[mysql]
loose-default-character-set = utf8
[WinMySQLadmin]
server = D:/Program Files/mysql/mysql-5.6.11-win32/bin/mysqld.exe
6、打开命令提示符,切换到D:Program Filesmysqlmysql-5.6.11-win32in目录下,然后执行mysqld -install安装mysql服务。执行成功后会提示:service successfully installed。如果想卸载mysql服务,执行mysqld -remove即可。
7、启动mysql服务:net start mysql
8、默认情况下root是空密码,给root设置密码:mysqladmin -u root -p password "新密码"
9、然后在命令提示符下执行mysql命令既可进入mysql,然后进行各种操作(建表、查询之类的)
最后推荐两篇mysql操作连接:
1、快速入门:http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html#c4
2、深入研究:http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html#database-use