CentOS7.5安装MySQL5.7压缩包
1、添加MySQL用户组及用户,不建议使用root用户安装
添加用户组
groupadd mysql
添加用户mysql到用户组mysql
useradd -g mysql mysql
修改mysql密码
passwd mysql
如下图
# 2、下载mysql
网址:https://cdn.mysql.com/archives/
可以自行选择版本
也可以使用weget下载
## 3、安装mysql
登录mysql用户
su root
安装 numactl
yum -y install numactl
解压缩
tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
重命名(个人习惯,将文件命名简单点,可以跳过),改名字后面可以省很多事
mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql
将mysql复制到/usr/local下面
cp -a mysql /usr/local/
进入/usr/local/
cd /usr/local/
将mysql文件夹赋予用户mysql和赋予其最高权限
chown -R mysql:mysql mysql
chmod 777 mysql
进入mysql目录
cd /usr/local/mysql
建立文件my.cnf
[client]
no-beep
socket = /tmp/mysql.sock
port=3306
[mysql]
default-character-set=utf8
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data
port=3306
log-error = /usr/local/mysql/data/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /tmp/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
#Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /usr/local/mysql/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
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
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
将my.cnf复制到/etc/
cp my.cnf /etc/
进入support-files,将mysql.server复制到/etc/init.d/mysql,设置mysql开机自启动
cd support-files
cp mysql.server /etc/init.d/mysqld
初始化mysql
/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql/ --datadir=/usr/local/mysql/data/
启动mysql服务
service mysql start
关闭mysql服务
service mysql stop
在my.cnf的[mysqld]下面加一句,重启服务,就可以不用密码登录root
skip-grant-tables
root登录
cd bin
./mysql -u root -p
然后更新root账户的密码为’root’
命令:
update mysql.user set authentication_string=password("root") where user="root";
然后输入flush privileges;(刷新账户信息)
flush privileges;
使用quit退出root用户,进入my.cnf删除skip-grant-tables
重新服务吗,使用root用户登录
将mysqld添加到开机自启
chkconfig --add mysqld