1、在安装mysql-5.6.28.tar.gz前,先安装编译环境
yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake
2、编译安装mysql
2.1 添加用户
groupadd mysql useradd -g mysql mysql2.2 编译安装
tar -zxvf mysql-5.6.28.tar.gz #默认情况下是安装在<span style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, 'monospace !important'; line-height: 18px; white-space: pre-wrap;">/usr/local/mysql</span> cd <span style="font-family: Arial, Helvetica, sans-serif;">mysql-5.6.28</span> cmake make && make install2.3 编译参数的设定
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=<span style="font-family:Arial, Helvetica, sans-serif;"><strong>/</strong>usr/local/</span>mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci;
2.4 改变mysql安装目录的所有者
chown -R mysql:mysql /usr/local/mysql
3、初始化数据库
cd /usr/local/mysql/scripts ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#使用默认配置文件 cp my-default.cnf /etc/my.cnf
cd /usr/local/mysql/support-files #注册服务 cp mysql.server /etc/rc.d/init.d/mysql #让chkconfig管理mysql服务 chkconfig --add mysql #开机启动 chkconfig mysql on
service mysql start #验证mysql启动成功 netstat -ant | grep 3306
7、配置mysql用户,修改root密码
Mysql启动成功后,root默认没有密码,我们需要设置root密码。
设置root密码之前,先设置PATH路径,以便能直接调用/usr/local/mysql/bin中的mysql等命令.
修改/etc/profile文件,在文件末尾加入
PATH=/usr/local/mysql/bin:$PATH export PATH
关闭文件,运行下面的命令,让配置立即生效
source /etc/profile
现在,可以在终端内直接输入mysql进入到mysql的环境了,修改密码
mysql -uroot -p mysql> SET PASSWORD = PASSWORD('123456');若要设置root用户可以远程访问,执行
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION
8、关闭防火墙,防止远程连接失败
1)重启后生效
开启: chkconfig iptables on 关闭: chkconfig iptables off2)立即生效
开启: service iptables start 关闭: service iptables stop
SHOW VARIABLES LIKE 'character%'修改mysql的、etc/my.cnf文件
[client] default-character-set=utf8 [mysqld] character-set-server=utf8 [mysql] default-character-set=utf8
问题: Starting MySQL..The server quit without updating PID file ([FAILED]/mysql/Server03.mylinux.com.pid). 解决: 修改/etc/my.cnf 中datadir,指向正确的mysql数据库文件目录
问题: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解决: 新建一个链接或在mysql中加入-S参数,直接指出mysql.sock位置。 ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock /usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql.sock
11、参考的博客文章
1、http://www.cnblogs.com/xiongpq/p/3384681.html
2、http://my.oschina.net/looly/blog/297980?fromerr=lIEQ7fha