基于 Centos6.10 安装mysql-5.7

准备环境

系统:Centos6.10

源码包存放目录:/data

软件安装目录:/usr/local/

安装yum依赖包

yum install -y gcc gcc-c++ readline-devel zlib-devel bison cmake wegt

下载安装boost

cd /data/
wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxvf boost_1_59_0.tar.gz
cd /data/boost_1_59_0/
./bootstrap.sh
./b2 install

下载安装mysql

cd /data/
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.23.tar.gz
tar -zxvf mysql-5.7.23.tar.gz
cd /data/mysql-5.7.23/

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1? -DWITH_ARCHIVE_STORAGE_ENGINE=1? -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/include/boost

make&&make install

创建用户并修改权限

groupadd mysql
useradd -g mysql mysql

chown mysql:mysql /usr/local/mysql/

初始化数据库

cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

修改配置文件

vim /etc/my.cnf

写入以下内容:

[mysqld]

basedir =/usr/local/mysql

datadir=/usr/local/mysql/data/

socket=/usr/local/mysql/data/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

创建mysqld.pid文件

mkdir /var/run/mysqld/
touch /var/run/mysqld/mysqld.pid
chown mysql:mysql /var/run/mysqld/
chmod -R 777 /var/run/mysqld/

设置开机启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld 
chkconfig --add mysqld

配置环境变量

 

echo "PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
source /etc/profile

启动停止数据库

service mysqld start(启动)
service mysqld stop(停止)

修改登录密码

cd /usr/local/mysql/bin/
./mysqld_safe --skip-grant-tables(进入数据库安全模式)
update mysql.user set authentication_string=password('123456') where user='root';
flush privileges;

--第一次修改密码时执行这条语句--
alter user user() identified by "123456";

 

你可能感兴趣的:(mysql)