yum -y install wget
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz -P /usr/local/src/
tar xzf /usr/local/src/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
yum -y install perl
useradd mysql -M -s /sbin/nologin
mkdir /data
cd /usr/local/mysql/
./scripts/mysql_install_db --user=mysql --datadir=/data
cp support-files/mysql.server /etc/init.d/mysqld
/bin/cp -f support-files/my-default.cnf /etc/my.cnf
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib64/
在上面的步骤中,我们把mysql的bin目录添加到环境变量中,要使其立即生效,可执行以下命令:
source /etc/profile
或者重新打开一个终端也可以。
安装完后修改一下配置文件,在[mysqld]下新增以下内容:
datadir = /data
character_set_server = utf8
log-bin = mysql-bin
innodb_file_per_table = 1
lower_case_table_names = 1
其中第一条是必须的,其他可选。
日常管理常用命令:
# 启动
/etc/init.d/mysqld start
# 停止
/etc/init.d/mysqld stop
# 重启
/etc/init.d/mysqld restart
# 开机自动启动
chkconfig mysqld on
# 禁止开机自动启动
chkconfig mysqld off
为root用户设置密码:
mysqladmin -u root password 'root'