源码安装mysql5.7

一、下载源码包,并解压
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35.tar.gz
tar xzf mysql-5.7.35.tar.gz
cd mysql-5.7.35/
二、安装依赖
yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel
三、进行cmake编译
cmake . -DCMAKE_INSTALL_PREFIX=/data/app/mysql-5.7.35 \
-DMYSQL_DATADIR=/data/app/mysql-5.7.35/data \
-DMYSQL_UNIX_ADDR=/data/app/mysql-5.7.35/tmp/mysql.sock \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/data/app/boost_1_59_0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=system \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
四、直接编译并安装
make && make install
五、创建相关的数据存放目录
cd /data/app
ln -s  /data/app/mysql-5.7.35 /usr/local/mysql
mkdir /data/app/mysql-5.7.35/{data,tmp}
touch /var/log/mysqld.log
chown -R mysql.mysql /data/app/mysql-5.7.35
chown -R mysql.mysql /var/log/mysqld.log
六、初始化
/data/app/mysql/bin/mysqld --initialize --user=mysql --basedir=/data/app/mysql --datadir=/data/app/mysql/data
初始化参数介绍:
  --initialize-insecure  不安全初始化,即没有密码。
  --initialize           安全初始化,会自动生成临时密码。在log-error里,查询 temporary password
  --user=mysql           初始化用户
  --basedir=/service/mysql        软件安装目录
  --datadir=/service/mysql/data   数据存放位置
七、编辑配置文件
vim /etc/my.cnf
	[mysqld]
	basedir=/data/app/mysql
	datadir=/data/app/mysql/data
	port=3306
	socket=/data/app/mysql/tmp/mysql.sock
	character-set-server=utf8mb4
	log-error=/var/log/mysqld.log
	pid-file=/data/app/mysql/tmp/mysqld.pid
	
	[mysql]
	socket=/data/app/mysql/tmp/mysql.sock
	
	[client]
	socket=/data/app/mysql/tmp/mysql.sock
八、加入systemd管理
cp mysql/support-files/mysql.server /etc/init.d/mysqld
vim /usr/lib/systemd/system/mysqld.service
	[Unit]
	Description=MySQL Server
	Documentation=man:mysqld(8)
	Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
	After=network.target
	After=syslog.target
	[Install]
	WantedBy=multi-user.target
	[Service]
	User=mysql
	Group=mysql
	ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
	LimitNOFILE = 5000
九、启动数据库
systemctl daemon-reload
systemctl start mysqld
十、查询默认初始密码
grep 'temporary password' /var/log/mysqld.log 
十一、测试连接

这里用到的密码,是第十步操作查看到的

 /data/app/mysql/bin/mysql -uroot -p'Kr:xLI)Bx8Ld'
	mysql: [Warning] Using a password on the command line interface can be insecure.
	Welcome to the MySQL monitor.  Commands end with ; or \g.
	Your MySQL connection id is 4
	Server version: 5.7.35
	
	Copyright (c) 2000, 2021, Oracle and/or its affiliates.
	
	Oracle is a registered trademark of Oracle Corporation and/or its
	affiliates. Other names may be trademarks of their respective
	owners.
	
	Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
	
	mysql> 
十二、设置环境变量
vim /etc/profile.d/mysql.sh
	export PATH=/data/app/mysql/bin:$PATH
source /etc/profile
十三、使用mysql命令连接
mysql -uroot -p'v><y4(H&BuSu'
	mysql: [Warning] Using a password on the command line interface can be insecure.
	Welcome to the MySQL monitor.  Commands end with ; or \g.
	Your MySQL connection id is 5
	Server version: 5.7.35
	
	Copyright (c) 2000, 2021, Oracle and/or its affiliates.
	
	Oracle is a registered trademark of Oracle Corporation and/or its
	affiliates. Other names may be trademarks of their respective
	owners.
	
	Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
	
	mysql> 
十四、在mysql环境里修改密码
mysql> alter user root@localhost identified by '20010405lhj..';
mysql> alter user root@localhost identified by '20010405Lhj..';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值