源码部署MySQL

MySQL

1.准备环境
关闭防火墙
[root@localhost ~]#systemctl stop firewalld
[root@localhost ~]#systemctl disable firewalld
关闭selinux
[root@localhost ~]#setenforce 0
[root@localhost ~]#sed -i '%s/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
验证是否通网
[root@localhost ~]#ping -W3 -c2  baidu.com
2.清理环境
[root@localhost ~]#yum -y erase mariadb mariadb-server mariadb-libs mariadb-devel
[root@localhost ~]#userdel -r mysql
[root@localhost ~]#rm -rf /etc/my*
[root@localhost ~]#rm -rf /var/lib/mysql
3.安装编译用的依赖包
[root@localhost ~]#yum -y groupinstall "Development Tools"
[root@localhost ~]#yum -y install ncurses ncurses-devel openssl-devel bison libgcrypt gcc gcc-c++ make cmake
4.创建MySQL用户
[root@localhost ~]#useradd -M -s /sbin/nologin mysql
5.创建所需目录
[root@localhost ~]#mkdir -p /usr/local/{mysql,tmp,log,date}
6.修改目录的所有者,所属组
[root@localhost ~]#chown mysql.mysql /usr/local/{mysql,tmp,log,date}
7.下载MySQL安装包
curl -o https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.40.tar.gz
8.解压MySQL安装包
[root@localhost ~]#tar -xvf mysql-boost-5.7.40.tar.gz
9.编译
[root@localhost ~]#cd mysql-5.7.40
[root@localhost mysql-5.7.40]#cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/local/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
10.安装编译
[root@localhost mysql-5.7.40]#make -j 2 && make install
11.修改权限
[root@localhost mysql-5.7.40]#chown -R mysql.mysql /usr/local/mysql
12.设置配置文件
[root@localhost ~]#vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql                    #安装目录
datadir = /usr/local/data                    #数据存放目录
tmpdir = /usr/local/tmp                      #/tmp缓存目录
socket = /usr/local/tmp/mysql.sock           #指定socket文件的位置
pid_file = /usr/local/tmp/mysqld.pid             #指定pid文件的位置
log_error = /usr/local/log/mysql_error.log   #错误日志的位置
slow_query_log_file = /usr/local/log/slow_warn.log  #慢日志查询

server_id = 1                       #server-id=??
user = mysql                        #指定用户
port = 3306                         #指定端口
bind-address = 0.0.0.0              #监听地址(允许所以ip访问)
character-set-server = utf8         #字符集
default_storage_engine = InnoDB     #引擎
13.初始化数据库
[root@localhost ~]#cd /usr/local/mysql
[root@localhost ~]#./bin/mysqld --user="mysql" --initialize
14.配置环境变量
[root@localhost ~]#echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@localhost ~]#source /etc/profile
15.获取密码
[root@localhost ~]#grep "password" /usr/local/log/mysql_error.log
16.启动MySQL
[root@localhost ~]#./bin/mysqld_safe --user="mysql"
17.验证是否启动
[root@localhost ~]#ss -nplt |  grep 3306
18.修改密码
[root@localhost ~]#mysqladmin -uroot -p'原密码' password '新密码'
19.拷贝启动文件
[root@localhost ~]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
20.使用systemctl管理 MySQL
[root@localhost ~]#systemctl daemon-reload
[root@localhost ~]#systemctl start mysqld

你可能感兴趣的:(mysql,数据库,linux)