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包,如下:
[root@tercel2 software]# ll
总用量 235392
-rw-r--r--@H_404_56@. 1 root root 27255297 10月 13 2016 glibc-2@H_404_56@.24@H_404_56@.tar@H_404_56@.gz
drwxrwxrwx@H_404_56@. 6 root root 4096 10月 13 2016 hadoop
-rw-r--r--@H_404_56@. 1 root root 138090286 10月 13 2016 jdk-7u80-linux-x64@H_404_56@.rpm
-rw-r--r--@H_404_56@. 1 root root 18763900 5月 12 18:16 MysqL-client-5@H_404_56@.6@H_404_56@.31-1@H_404_56@.el6@H_404_56@.x86_64@H_404_56@.rpm
-rw-r--r--@H_404_56@. 1 root root 56914268 5月 12 18:16 MysqL-server-5@H_404_56@.6@H_404_56@.31-1@H_404_56@.el6@H_404_56@.x86_64@H_404_56@.rpm
c. 安装MysqL
[root@tercel2 software]# rpm -ivh MysqL-client-5.6.31-1.el6.x86_64.rpm
[root@tercel2 software]# rpm -ivh MysqL-server-5.6.31-1.el6.x86_64.rpm
#修改配置文件位置
[root@tercel2 software]# vim /usr/my.cnf
d. 初始化MysqL及设置密码
[root@tercel2 software]# service MysqL start
[root@tercel2 software]# cat /root/.MysqL_secret
# The random password set for the root user at Fri May 12 18:19:25 2017 (local time): VrEzOpd1w8NtYz03
[root@tercel2 software]# MysqL -uroot -pVrEzOpd1w8NtYz03
MysqL> SET PASSWORD = PASSWORD(@H_404_56@'combanc');
Query OK,0 rows affected (0.00 sec)
MysqL> exit;
[root@tercel2 software]# MysqL -uroot -pcombanc
e. 远程登陆用户设置
MysqL> use MysqL;
MysqL> select host,user,password from user; +-----------+------+-------------------------------------------+
| host | user | password | +-----------+------+-------------------------------------------+
| localhost | root | *412DA40DD727FEE727D2E974F9DC708C45E0D08B | | tercel2 | root | *432EA25EFB6FD6185A072710D0878B0819E328AF |
| 127.0.0.1 | root | *432EA25EFB6FD6185A072710D0878B0819E328AF | | ::1 | root | *432EA25EFB6FD6185A072710D0878B0819E328AF |
+-----------+------+-------------------------------------------+
4 rows in set (0.03 sec)
MysqL> update user set password=password('combanc') where user='root';
MysqL> update user set host='%' where user='root' and host='localhost';
MysqL> flush privileges;
MysqL> exit;
f. 设置开机自启动
[root@tercel2 software]# chkconfig MysqL on
[root@tercel2 software]# chkconfig --list | grep MysqL
MysqL 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
g. MysqL的默认安装位置
/var/lib/MysqL/ #数据库目录
/usr/share/MysqL #配置文件目录
/usr/bin #相关命令目录
/etc/init.d/MysqL #启动脚本
h. 修改字符集和数据存储路径
配置/usr/my.cnf文件,修改数据存放路径、MysqL.sock路径以及默认编码utf-8.
[client]
port = 13306
default-character-set=utf8
[MysqLd]
port = 13306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
log_error = /var/log/MysqL/error.log
#错误日志路径自己定义,前提是目录必须存在
#(注意linux下MysqL安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)
lower_case_table_names=1
#(设置最大连接数,默认为 151,MysqL服务器允许的最大连接数16384; )
max_connections=1000
[MysqL]
default-character-set = utf8
可查看字符集
show variables like @H_404_56@'%collation%';
show variables like @H_404_56@'%char%';
I.如果想远程连接登录MysqL则需要:授权,并关闭防火墙或添加防火墙规则。
GRANT ALL PRIVILEGES ON *.* TO @H_404_56@'root'@@H_404_56@'%' IDENTIFIED BY @H_404_56@'combanc' WITH GRANT OPTION;
2.关闭防火墙
service iptables stop 关闭命令
chkconfig iptables off 永久关闭防火墙
service iptables status
3.添加防火墙规则
[root@tercel2 software]# vi /etc/sysconfig/iptables
加入下面这行
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 13306 -j ACCEPT
service iptables restart #重启防火墙
4.最重要的
vi /etc/selinux/config
设置 SELINUX=disabled
否则会出现Can't start server: Bind on TCP/IP port: Permission denied的错误
5.重启服务器