Centos7.9安装Mysql5.7.38
环境:Centos7.9 ,mysql5.7.38
软件包:mysql官方下载tar包
下载地址:https://downloads.mysql.com/archives/community/
0x00.创建软件包上传目录
mkdir /soft
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-el7-x86_64.tar
#解压
tar -xvf mysql-5.7.38-el7-x86_64.tar -C /usr/local
cd /usr/local/ && mv mysql-5.7.38-el7-x86_64 myql
0x01.安装mysql需要用到的依赖包libaio,该依赖包可提高数据库IO性能
yum install -y libaio
0x02.创建mysql系统用户,用于管理mysql数据库,尽量不使用root用户去参与软件应用
#创建mysql用户组
groupadd mysql
#创建mysql用户,系统用户用来跑服务
useradd -r -g mysql -s /sbin/nologin mysql
0x03. 更改目录属主和属组
chown -R mysql.mysql /usr/local/mysql
编辑my.cnf文件
vi /etc/my.cnf
[mysqld] user=mysql port = 3306 socket = /var/lib/mysql/mysql.sock datadir = /var/lib/mysql character-set-server=utf8 server-id = 1 max_connections = 1000 group_concat_max_len = 102400 max_connect_errors = 10 table_open_cache = 4096 event_scheduler = ON skip-name-resolve lower_case_table_names = 1 max_allowed_packet = 64M binlog_cache_size = 32M max_heap_table_size = 256M read_rnd_buffer_size = 64M sort_buffer_size = 256M join_buffer_size = 512M thread_cache_size = 300 log_bin_trust_function_creators=1 key_buffer_size = 256M read_buffer_size = 32M read_rnd_buffer_size = 128M bulk_insert_buffer_size = 512M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ######READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE transaction_isolation = READ-COMMITTED tmp_table_size = 512M log-bin=mysql-bin binlog_format=mixed expire_logs_days = 15 slow_query_log = 1 slow_query_log_file = /var/lib/mysql/slow.log long_query_time = 5 ####### InnoDB innodb_buffer_pool_size = 512M innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 32M innodb_log_file_size = 1024M innodb_log_files_in_group = 4 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 #innodb_force_recovery=1 [mysqldump] quick max_allowed_packet = 64M [mysql] no-auto-rehash [myisamchk] key_buffer = 16M sort_buffer_size = 16M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] open-files-limit = 65535 log-error=/var/lib/mysql/mysqld.log pid-file=/var/lib/mysql/mysqld.pid
0x04. 初始化mysql
首先配置环境变量
vi /root/.bashrc #在文末追加 export path=/usr/local/mysql/bin:$PATH #使配置生效 source /root/.bashrc
cd /usr/local/mysql bin/mysqld --initialize --user=mysql
#注意查看随机生成的密码
grep "temporary password" /var/log/mysql
#安装加密算法,本次不安装
bin/mysql_ssl_rsa_setup
#使用systemctl控制mysql服务的启停
#编辑 /etc/systemd/system/mysqld.service vi /etc/systemd/system/mysqld.service #以下是文件内容,注意修改启动路径以及配置文件路径 [Unit] Description=Mysql Server5.7 After=network.service [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql Type=forking TimeoutSec=0 PermissionsStartOnly=true ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize LimitNOFILE=5000 Restart=on-failure RestartSec=10 RestartPreventExitStatus=1 PrivateTmp=false
#启动之前创建mysql的sock的软连接
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
#启动并使用临时密码登录mysql
systemctl start mysqld.service
systemctl enable mysqld.service
mysql -uroot -p
#修改密码
set password='xxxxxx';
至此,mysql5.7 安装完毕