在centos 6 下安装mysql 5.6

    因为工作需要,要在redhat环境下用mysql,没想到与win下使用mysql有些区别,踩了几个坑,于是有这篇入门安装手册。

==========分割线========

  1. 下载

    用的是2进制包,源码包还要折腾,就不弄了,32位的地址 http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.12-linux-glibc2.5-i686.tar.gz 包有点儿大,285M   

  2. 安装
    参考解压后目录下的文件INSTALL-BINARY,里面有一段脚本,按着上面一步步执行下来就好
    shell> groupadd mysql
    shell> useradd -r -g mysql mysql
    shell> cd /usr/local
    shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
    shell> ln -s full-path-to-mysql-VERSION-OS mysql
    shell> cd mysql
    shell> chown -R mysql .
    shell> chgrp -R mysql .
    shell> scripts/mysql_install_db --user=mysql
    shell> chown -R root .
    shell> chown -R mysql data
    # Next command is optional
    shell> cp support-files/my-medium.cnf /etc/my.cnf
    shell> bin/mysqld_safe --user=mysql &
    # Next command is optional
    shell> cp support-files/mysql.server /etc/init.d/mysql.server
  3. 踩坑之一:修改root密码
    默认登录是不要密码的,直接用bin/mysql就进去了,安全系数太低
    mysql> select host, user, password from mysql.user;
    显示当前所有用户信息,可以看见密码全为空,还有匿名帐号
    删除匿名
    mysql> DELETE FROM mysql.user WHERE User = '';
    替换root密码
    SET PASSWORD FOR root@"相关host" = PASSWORD('你的密码');
    FLUSH PRIVILEGES;

  4. 踩坑之二:允许远程链接
    首先,要确保防火墙没有阻拦3306端口,切记!为了这个我排查了2个钟头……
    然后,加入允许远程登录的用户信息
    GRANT USAGE ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
    FLUSH PRIVILEGES;

  5. 踩坑之三:字符集
    mysql默认的字符集是坑爹的拉丁文,最好换成utf8
    编辑 /etc/my.cnf
    [mysqld]
    # 添加字符集指定
    character-set-server=utf8
    然后重启mysql服务,进去看看字符集对了没
    mysql> \s
    --------------
    /usr/local/mysql/bin/mysql  Ver 14.14 Distrib 5.6.12, for linux-glibc2.5 (i686) using  EditLine wrapper
    
    Connection id:		2
    Current database:	
    Current user:		root@localhost
    SSL:			Not in use
    Current pager:		stdout
    Using outfile:		''
    Using delimiter:	;
    Server version:		5.6.12 MySQL Community Server (GPL)
    Protocol version:	10
    Connection:		Localhost via UNIX socket
    Server characterset:	utf8
    Db     characterset:	utf8
    Client characterset:	utf8
    Conn.  characterset:	utf8
    UNIX socket:		/tmp/mysql.sock
    Uptime:			27 sec


你可能感兴趣的:(mysql)