我爱编程

Centos6.9 安装Mysql

2017-05-15  本文已影响0人  9995857

安装Mysql5.7

将mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz 拷贝到/soft下

  1. 创建组和不可登录用户
    groupadd mysql
    useradd -r -g mysql -s /bin/false mysql

  2. 依赖安装 (可能需要)
    yum -y install libaio libaio-devel

  3. 解压安装
    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

  4. 修改配置文件
    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=utf8

basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock

  1. 修改环境变量
    vi /etc/profile

MYSQL_HOME=/usr/local/mysql
PATH=$MYSQL_HOME/bin:$PATH
export MYSQL_HOME PATH

source /etc/profile

  1. 初始化数据库
    cd /usr/local/mysql
    这里会有一个随机密码,请记牢
    mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

  2. 制作启动文件
    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

  1. 启动停止服务
    service mysql start
    mysql -uroot -p
    进入后必须更改密码,否则不允许操作
    SET PASSWORD = PASSWORD('newpasswd');
    service mysql stop
上一篇下一篇

猜你喜欢

热点阅读