Centos Install Mysql (解压缩版)

下载并解压Mysql

下载地址http://dev.mysql.com/downloads/mysql/ (选择Linux - Generic版本的Linux - Generic (glibc 2.5) (x86, 64-bit), Compressed)

# 检查库文件是否存在,如有删除。
rpm -qa | grep mysql
rpm -e mysql-libs-5.1.52.x86_64 --nodeps

# 下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

# 解压
tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql

添加用户及用户组

# 检查mysql用户及用户组是否存在
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql

# 创建mysql用户及用户组
groupadd mysql
useradd -r -g mysql mysql

授权

# 授权
cd /usr/local
chown -R mysql:mysql mysql/

安装

cd mysql

# 初始化(这里要记录下密码,后续会用到)
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

# 创建执行程序软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

#启动mysql
./support-files/mysql.server start

# 拷贝文件到开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --list mysqld # 如果不存在则执行下面命令,存在则不执行下面命令
chkconfig --add mysqld

配置my.cnf

vi /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
user=mysql
character-set-server=utf8
collation-server=utf8_general_ci
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

初始化密码

mysql -u root -h 127.0.0.1 -p
# 这里的密码是刚才初始化时生成的随机密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
flush privileges;

常用命令

service mysqld start
service mysqld stop
service mysqld restart

There are no comment yet.

HTML tag cannot be used in this comment.