环境: CentOS7 软件:MySQL5.6.26
建议安装之前先运行以下命令将所需环境配置好:
yum install libaio #安装libaio
yum install deltarpm #安装deltarpm
yum install perl-Data-Dumper.x86_64 #安装Perl模块
1 下载MySQL 源码包
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
2 解压下载的文件到/usr/local目录并修改文件夹名称为mysql
tar -zxvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz -C /usr/local
mv mysql-5.6.26-linux-glibc2.5-x86_64/ mysql
3创建Mysql用户和用户组
useradd mysql -s /sbin/nologin
4创建Mysql数据库目录并赋予权限给Mysql用户
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /usr/local/mysql
5进入/usr/local/mysql目录 初始化mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
6 备份系统自带的my.cnf文件,然后把Mysql解压目录中默认配置文件移过去
mv /etc/my.cnf /etc/my.cnf.bak
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
7修改my.cnf文件
datadir=/data/mysql
port=3306
socket=/tmp/mysql.sock
8复制解压目录下面的mysql.server文件到/etc/init.d/mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vi /etc/init.d/mysqld
datadir=/data/mysql #修改数据库目录文件
basedir=/usr/local/mysql
9 启动mysql服务
service mysqld start
Usage: mysqld {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
10 配置mysql的环境变量
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
11 登录mysql
[root@localhost ~]# mysql -uroot -p #第一次登录不需要密码 直接按回车
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.26 MySQL Community Server (GPL)
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> update mysql.user set password=password("123456") where user="root"; #修改root 密码
flush privileges;
12 设置字符编码为UTF-8
请参考:Linux下MySQL 5.5/5.6的修改字符集编码为UTF8。 安装完成。