mysql5.7版本源码安装

1,本地上传或者下载MySQL源码安装包到服务器
1.1,进入安装的目录,并解压
cd /opt && tar -zxf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
1.2,修改MySQL目录名称,并创建软链接
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql-5.7.24

ln -s mysql-5.7.24 mysql
1.3,安装所需依赖

使用阿里云的yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum install -y libaio*
1.4,写入MySQL配置文件
cat >/opt/mysql/my.ini<<EOF
[client]
port=3306 #端口号
default-character-set=utf8 #编码
socket = /opt/mysql/run/mysql.socket 
[mysqld]
port=3306 
basedir=/opt/mysql #MySQL的目录位置
datadir=/opt/mysql/data #数据目录
max_connections=2048 #最大连接数
wait_timeout = 10000 
interactive_timeout = 10000
character-set-server=utf8
lower_case_table_names=1
max_allowed_packet = 200M
default-time-zone='+8:00'
binlog-format=ROW
character-set-server=utf8
default-storage-engine=INNODB
sql_mode= STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
long_query_time=10
server-id=1
max_connections=151
query_cache_size=0
table_open_cache=2000
tmp_table_size=58M
thread_cache_size=10
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=107M
key_buffer_size=8M
read_buffer_size=64K
read_rnd_buffer_size=256K
innodb_flush_log_at_trx_commit=1
#innodb_log_buffer_size=1M
innodb_buffer_pool_size=1G
innodb_buffer_pool_chunk_size=128M
innodb_log_file_size=48M
innodb_thread_concurrency=17
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
log_slow_queries = /usr/local/mysql/var/slow_queries.log #慢查询日志路径 
long_query_time = 5 #记录SQL查询超过5s的语句 
log-queries-not-using-indexes = 1 #记录没有使用索引的sql 
back_log=80
flush_time=0
join_buffer_size=256K
max_connect_errors=100
open_files_limit=4161
query_cache_type=0
sort_buffer_size=256K
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
EOF
1.5,创建MySQL数据库目录
mkdir -p /opt/mysql/{data,run}
1.6,创建MySQL用户,并授权
useradd -M -s /sbin/nologin/ mysql && chown -R mysql.mysql /opt/mysql-5.7.24
1.7,写入环境变量
echo "export PATH=/opt/mysql/bin:$PATH" >>/etc/profile && source /etc/profile
1.8,初始化MySQL,并提取初始密码
mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --socket=/opt/mysql/run/mysql.socket
#取出密码2018-11-27T07:57:57.376667Z 1 [Note] A temporary password is generated for root@localhost: T/vGiZgP0o,S(此处为初始化密码)
执行后会输出如下:(结尾处为初始密码)
2021-08-04T03:05:49.694620Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-04T03:05:49.930724Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-04T03:05:49.979363Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-04T03:05:50.040117Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: df3999b4-f4d0-11eb-935e-fa163e0defed.
2021-08-04T03:05:50.041939Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-04T03:05:50.042546Z 1 [Note] A temporary password is generated for root@localhost: lf?;dnbh1(3C
root@localhost: 《 lf?;dnbh1(3C 》 初始密码
1.9,启动MySQL
mysqld_safe --defaults-file=/opt/mysql/my.ini &
2,安装完成,进行登录MySQL
2.1,登录MySQL
输入刚才提取的初始密码:“ lf?;dnbh1(3C ”
mysql -uroot -p -S /opt/mysql/run/mysql.socket
2.2,创建MySQL密码
set password for root@localhost = password('123456');

flush privileges;
2.3,创建root远程连接,并授权
grant all on *.* to root@'%' identified by '123456';

flush privileges;
2.4,创建普通用户和分库
CREATE DATABASE `new_db ` CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE USER 'test'@'%' IDENTIFIED BY '123456';

grant all on *.* to test@'%' ;

flush privileges;
以上是源码安装MySQL5.7版本数据库,配置文件根据需求来更改
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值