MySQL数据库5.7的编译安装过程

一、安装Mysql环境依赖包

[root@localhost ~]#yum -y install \
gcc \
gcc-c++ \
make \
ncurses \
ncurses-devel \
bison \
cmake

二、创建运行用户

[root@localhost ~] useradd -s /sbin/nologin mysql

三、编译安装

获取mysql-boost-5.7.20.tar.gz安装包到opt目录下

[root@localhost ~]cd /opt
[root@localhost opt]# tar xzvf mysql-boost-5.7.20.tar.gz
[root@localhost opt]#cd /opt/mysql-5.7.20/
[root@localhost mysql-5.7.20]#
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

[root@localhost mysql-5.7.20]#make -j3
[root@localhost mysql-5.7.20]#make install

四、数据库目录权限调整

chown -R mysql:mysql /usr/local/mysql/

五、建立调整配置文件

vi /etc/my.cnf

[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES


chown mysql:mysql /etc/my.cnf

六、设置环境变量

echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile

cd /usr/local/mysql/

bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
netstat -anpt | grep 3306

mysqladmin -u root -p password "abc123" //刚开始没密码是空的直接回车,然后输入密码abc123,这是新密码,此时新密码已经设立完成,因为是明文,所以会有warning不安全,abc123,这是在root账户下运行的

mysql -u root -p     ##这个命令敲下,提示要输入密码,这个就是刚才设置的密码abc123

猜你喜欢

转载自blog.csdn.net/m0_47452405/article/details/108579768
今日推荐