mysql 5.7 编译安装
- 操作系统: centos8.3
- 安装版本: mysql5.7.34
- 不带boost编译安装
dnf -y install gcc gcc-c++ ncurses ncurses-devel cmake
#不带boost编译安装
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34.tar.gz
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
#安装boost
tar xzf boost_1_59_0.tar.gz
cd boost_1_59_0
./bootstrap.sh
./b2 install
#创建mysql用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
#预编译安装
cd mysql-5.7.34
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL-USER=mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
make
make install
#添加启动项
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#初始化数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
# 启动数据库
systemctl start mysqld
#获取临时密码
cat /var/log/mysql/mysqld.log|grep pass|awk '{print $NF}'
带boost mysql5.7安装
#带boost mysql5.7安装
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.34.tar.gz
tar -xf mysql-boost-5.7.34.tar.gz
cd mysql-.5.7.34
#预编译
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
make -j 4 && make install
#赋权
chown -R mysql /usr/local/mysql
#初始化数据库
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#拷贝配置文件
cp support-files//my-default.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
vi /etc/profile
# 在profile文件末尾增加两行
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
#使PATH搜索路径立即生效:
source /etc/profile
# 启动数据库
systemctl start mysqld
#获取临时密码
cat /var/log/mysql/mysqld.log|grep pass|awk '{print $NF}'
mysql8.0 安装
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
tar -xf mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz
mkdir /mysql
mv mysql-8.0.22-linux-glibc2.12-x86_64/* /mysql
#创建用户与组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
mkdir -p /data/{mysqldata,binlog,log,relaylog}
chown -R mysql:mysql /data
#初始化
cd /mysql/bin
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/mysql --datadir=/data/mysqldata --tmpdir=/data/tmp
#制作软链接 添加/etc/profile PATH也可
ln -s /mysql/bin/{mysql,mysqldump,mysqladmin} /usr/bin/
#添加启动项
cp /mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
systemctl enable mysqld
service mysqld start
#获取临时密码
cat /var/log/mysql/mysqld.log|grep pass|awk '{print $NF}'
rpm包安装mysql8
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-server-8.0.26-1.el8.x86_64.rpm
dnf install mysql-community-server-8.0.26-1.el8.x86_64.rpm -y
dnf install mysql-server -y
systemctl start mysqld && systemctl enable mysqld