MySQL编译安装
安装依赖环境
yum -y groupinstall "Development Tools"yum -y install ncurses ncurses-devel openssl-devel bison libgcrypt gcc gcc-c++ make cmake
下载MySQL安装包
可自行在官网获取所需版本
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
在系统中添加运行mysqld进程的用户mysql
groupadd mysqluseradd -M -g mysql -s /sbin/nologin mysql
在系统中添加自定义mysql数据库目录及其他必要目录
mkdir -p /usr/local/{data,mysql,log,tmp}chown -R mysql:mysql /usr/local/{data,mysql,log,tmp}
将mysql-boost-5.7.24.tar.gz解压到当前目录,并执行部署操作
tar xf mysql-boost-5.7.24.tar.gzcd mysql-5.7.24·······························cmake . \-DWITH_BOOST=boost/boost_1_59_0/ \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DSYSCONFDIR=/etc \-DMYSQL_DATADIR=/usr/local/mysql/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_READLINE=1 \-DWITH_SSL=system \-DWITH_EMBEDDED_SERVER=1 \-DENABLED_LOCAL_INFILE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1make -j `lscpu | awk 'NR==4{ print $2 }'`echo $? #检验编译安装过程是否出错,成功返回0make install
mysql编译安装后
初始化MySQL安装配置
提升MySQL命令为系统级别命令
[root@mysql_source ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin'>>/etc/profile[root@mysql_source ~]# source /etc/profile(source命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。)
拷贝默认配置文件至/etc/my.cnf中
[root@mysql_source mysql]# chown -R mysql.mysql /usr/local/mysql[root@mysql_source ~]# cd /usr/local/mysql/mysql-test/include[root@mysql_source include]# cp /etc/{my.cnf,my.cnf.bak}[root@mysql_source include]# 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 #引擎
执行数据库服务初始化操作
[root@mysql_source mysql]# mysqld --defaults-file=/etc/my.cnf --initialize --user='mysql'
启动mysqld服务
[root@mysql_source mysql]# mysqld_safe --defaults-file=/etc/my.cnf &
配置mysqld服务的管理工具(便于启动)
[root@mysql_source support-files]# cd /usr/local/mysql/support-files[root@mysql_source support-files]# cp mysql.server /etc/init.d/mysqld[root@mysql_source support-files]# chkconfig --add mysqld[root@mysql_source support-files]# chkconfig mysqld on
登录数据库并进行更改密码
[root@mysql_source mysql]# grep "password" /usr/local/log/mysql_error.log[root@mysql_source tmp]# mysql -uroot -p"ejhszb2:m3wJ"mysql> alter user 'root'@'localhost' identified by "Qwer@123";
来源地址:https://blog.csdn.net/m0_73629638/article/details/131371170