Centos6.9 安装Mysql
安装Mysql5.7
将mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz 拷贝到/soft下
-
创建组和不可登录用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
-
依赖安装 (可能需要)
yum -y install libaio libaio-devel
-
解压安装
tar -zxvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.16-linux-glibc2.5-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/data
-
修改配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
[mysql]
default-character-set=utf8[mysqld]
character_set_server=utf8basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
- 修改环境变量
vi /etc/profile
MYSQL_HOME=/usr/local/mysql
PATH=$MYSQL_HOME/bin:$PATH
export MYSQL_HOME PATH
source /etc/profile
-
初始化数据库
cd /usr/local/mysql
这里会有一个随机密码,请记牢
mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
-
制作启动文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
vi /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
- 启动停止服务
service mysql start
mysql -uroot -p
进入后必须更改密码,否则不允许操作
SET PASSWORD = PASSWORD('newpasswd');
service mysql stop