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 mysql
2.2 编译安装
tar -zxvf mysql-5.6.28.tar.gz
#默认情况下是安装在/usr/local/mysql
cd mysql-5.6.28
cmake . -LH (使用默认属性编译)
make && make install
2.3.1 编译参数的设定
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=/tmp/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.3.2 完整版
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=/tmp/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
#让mysql用户,具有写的权限(默认具有)
3、初始化数据库
cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#使用默认配置文件
cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf
#修改配置文件,添加下面的内容
#socket适用于,通信的,一定要添加
#socket的位置和cmake时mysql的-DMYSQL_UNIX_ADDR=/tmp/mysql.sock的路径,socket的路径地址要和前面的地址一样(不然mysql服务不能正常启动.)
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysql.pid
user = mysql
socket= /tmp/mysql.sock
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
关于怎么修改root用户密码1:
#将'new-password'改成自己的密码
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
关于怎么修改root用户密码2:
现在,参考博客,地址是http://blog.csdn.net/zbw18297786698/article/details/54235943
使用root用户登录mysql:
#要输入的密码,就是上面设置的密码
[root@VM_13_53_centos support-files]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.28 Source distribution
Copyright (c) 2000, 2015, 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.
mysql>
若要设置root用户可以远程访问,执行
#将下面的'password'改成自己的密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> flush privileges;
9、关闭防火墙,防止远程连接失败
1)重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
2)立即生效
开启: service iptables start
关闭: service iptables stop
3)开放3306端口
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
service iptables restart
10、改变编码,防止乱码
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 添加socket的配置
问题:
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
12、参考的博客文章
1、http://www.cnblogs.com/xiongpq/p/3384681.html
2、http://my.oschina.net/looly/blog/297980?fromerr=lIEQ7fha
13、Mysql的下载
下载地址