Linux下安装最新版MySQL

1. 下载 Linux 版本 MySQL 压缩包

下载命令:

命令 : wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz  # 下载地址

下载进度如图所示:

m_e1ae36e09a3ee020d6d4b9e74dcb3f9b_r

2. 解压

命令 : xz -d mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
#将.xz压缩包解压为.tar

命令 : tar xf mysql-8.0.19-linux-glibc2.12-x86_64.tar
#将.tar压缩包解压为文件夹

命令 : mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql/
#移动至安装目录,这里是 /usr/local/mysql

操作流程如图:

m_537bc2bfaffb553b87354c75afb66258_r

3. 给MySQL建立系统账号

 命令 : adduser mysql

4. 新建data、sql_log、undo目录

进入 MySQL 安装目录:

 命令 : cd /usr/local/mysql

新建data、sql_log、undo目录:

 命令 : mkdir data sql_log undo

给这三个目录建立属主:

 命令 : chown mysql:mysql -R data/ sql_log/ undo

如图所示:

m_c70423d8da36521eedd53f5622f2c2a2_r

5. 添加mysql环境变量

 命令 : vim /etc/profile

m_ec2831081170aec289d6bf404d73e7cc_r

在 profile 文件末尾添加如下内容(按i编辑):

export PATH=$PATH:/usr/local/mysql/bin

如下图所示:

m_5b760259e328a181b91eadbc52f2a01e_r

按ESC,然后输入:wq保存退出,如图所示:

m_473f2f74848c0ad1626ae28d2f371f84_r

使上述配置生效:

 命令 : source /etc/profile

6. 新建MySQL配置文件

新建my.cnf配置文件:

 命令 : vim /etc/my.cnf

在my.cnf中添加如下内容:

[client]
port = 30386
socket = /usr/local/mysql/data/mysql.sock

[mysqld]
#禁止DNS服务器连接
skip_name_resolve = 1
#跳过外部锁定
skip_external_locking = 1
#禁用符号链接以防止各种安全风险
skip_symbolic_links = 1
#启动用户
user = mysql
#默认的存储引擎
default_storage_engine = InnoDB
#用来指定socket文件的路径
socket  = /usr/local/mysql/data/mysql.sock
#用来指定pid文件的路径
pid_file = /usr/local/mysql/data/mysqld.pid

basedir = /usr/local/mysql

port = 30386

bind-address = 0.0.0.0

explicit_defaults_for_timestamp = off

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

key_buffer_size = 32M

#myisam_recover = FORCE,BACKUP

# undo log #

innodb_undo_directory = /usr/local/mysql/undo

#innodb_undo_tablespaces = 8s

# SAFETY #

max_allowed_packet = 64M
#允许多少个连续的中断连接请求
max_connect_errors = 100

sysdate_is_now = 1

#innodb = FORCE

#innodb_strict_mode = 1

secure-file-priv='/tmp'
# 默认使用"mysql_native_password"插件认证
default_authentication_plugin='mysql_native_password'

# Replice #

server-id = 1001
#定义relay_log的位置和名称
#relay_log = mysqld-relay-bin

gtid_mode = on

enforce-gtid-consistency

log-slave-updates = on

master_info_repository =TABLE

relay_log_info_repository =TABLE


# DATA STORAGE #

datadir = /usr/local/mysql/data/

tmpdir = /tmp



# BINARY LOGGING #

log_bin = /usr/local/mysql/sql_log/mysql-bin

max_binlog_size = 1000M

binlog_format = row

binlog_expire_logs_seconds=2592000

# sync_binlog = 1

# CACHES AND LIMITS #

tmp_table_size                 = 32M

max_heap_table_size            = 32M

max_connections                = 4000

thread_cache_size              = 2048

open_files_limit               = 65535

table_definition_cache         = 4096

table_open_cache               = 4096

sort_buffer_size               = 2M

read_buffer_size               = 2M

read_rnd_buffer_size           = 2M

# thread_concurrency             = 24

join_buffer_size = 1M

# table_cache = 32768

thread_stack = 512k

max_length_for_sort_data = 16k

# INNODB #

innodb_flush_method            = O_DIRECT

innodb_log_buffer_size = 16M

innodb_flush_log_at_trx_commit = 2

innodb_file_per_table          = 1

innodb_buffer_pool_size        = 256M

#innodb_buffer_pool_instances = 8

innodb_stats_on_metadata = off

innodb_open_files = 8192

innodb_read_io_threads = 16

innodb_write_io_threads = 16

innodb_io_capacity = 20000

innodb_thread_concurrency = 0

innodb_lock_wait_timeout = 60

innodb_old_blocks_time=1000

innodb_use_native_aio = 1

innodb_purge_threads=1

innodb_change_buffering=all

innodb_log_file_size = 64M

innodb_log_files_in_group = 2

innodb_data_file_path  = ibdata1:256M:autoextend

innodb_rollback_on_timeout=on

# LOGGING #

log_error = /usr/local/mysql/sql_log/mysql-error.log

# log_queries_not_using_indexes = 1

# slow_query_log = 1

slow_query_log_file = /usr/local/mysql/sql_log/slowlog.log

# TimeOut #

#interactive_timeout = 30

#wait_timeout        = 30

#net_read_timeout = 60

[mysqldump]

quick

max_allowed_packet = 100M

[mysql]

no-auto-rehash

# Remove the next comment character if you are not familiar with SQL

#safe-updates



[myisamchk]

key_buffer_size = 16M

sort_buffer_size = 5M

read_buffer = 2M

write_buffer = 2M



[mysqlhotcopy]

interactive-timeout

如图所示 :

m_2f3b404123a137d00a365c0e001b0774_r

7. 初始化MySQL

进入 MySQL 安装目录:

 命令 : cd /usr/local/mysql

执行初始化:

 命令 : mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
 #需要耐心等待

Tips:在初始化过程中如果出现一下输出:

mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory,可以使用命令:

可以使用命令 yum -y install numactl 来解决。

出现这个错误是因为Linux缺少软件依赖包numactl,上述命令时通过yum仓库安装numactl依赖包。

8. 查询MySQL初始临时密码

进入 “/usr/local/mysql/sql_log”, 使用如下命令可查看初始临时密码,请做好相关记录,后面登录需要用到:

 命令 : cd /usr/local/mysql/sql_log

 命令 : grep password mysql-error.log

如图所示 :

m_fd59705c7564c9b8b7f5296027ce9242_r

9. 关闭 Linux 防火墙

新手在安装学习MySQL,通常会出现端口号被防火墙阻止了,从而一直接连不上MySQL,所以为了方便后面连接MySQL学习,可以关闭Linux防火墙:

  命令 : systemctl status firewalld
  #查看防火状态

  命令 : systemctl disable firewalld
  #关闭防火墙

10. 关闭selinux

SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制设计的一个安全系统,但其对很多软件比较敏感,会导致很多服务崩溃,所以建议关闭:
编辑selinux配置文件:

  命令 :vim /etc/selinux/config

将selinux中参数改为”SELINUX=disabled”,按ESC,输入”:wq”保存退出,并使配置立即生效

  命令 : source /etc/selinux/config 

将其中参数改为SELINUX=disabled,并使配置立即生效

  命令 : source /etc/selinux/config   

如图所示:

m_744b6337507bfa06c12f8ecb35ccfccc_r

11. 启动、停止、重启MySQL

进入”/usr/local/mysql/support-files”,操作命令:

 命令 : cd /usr/local/mysql/support-files

 命令 : cp mysql.server /etc/init.d/mysql.d

MySQL 服务命令 :

 命令 : service mysqld start 
 #MySQL服务启动

 命令 : service mysqld stop
 #MySQL服务停止

 命令 : service mysqld reload
 #MySQL服务重启
 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:小林博客 www.vvso.cn小林博客 » Linux下安装最新版MySQL
分享到: 更多 (0)

评论 抢沙发

切换注册

登录

忘记密码 ?

切换登录

注册