版MySQ下安装最新

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 = 30386socket = /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.pidbasedir = /usr/local/mysqlport = 30386bind-address = 0.0.0.0explicit_defaults_for_timestamp = offsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLESkey_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 = 100sysdate_is_now = 1#innodb = FORCE#innodb_strict_mode = 1secure-file-priv='/tmp'# 默认使用"mysql_native_password"插件认证default_authentication_plugin='mysql_native_password'# Replice #server-id = 1001#定义relay_log的位置和名称#relay_log = mysqld-relay-bingtid_mode = onenforce-gtid-consistencylog-slave-updates = onmaster_info_repository =TABLErelay_log_info_repository =TABLE# DATA STORAGE #datadir = /usr/local/mysql/data/tmpdir = /tmp# BINARY LOGGING #log_bin = /usr/local/mysql/sql_log/mysql-binmax_binlog_size = 1000Mbinlog_format = rowbinlog_expire_logs_seconds=2592000# sync_binlog = 1# CACHES AND LIMITS #tmp_table_size                 = 32Mmax_heap_table_size            = 32Mmax_connections                = 4000thread_cache_size              = 2048open_files_limit               = 65535table_definition_cache         = 4096table_open_cache               = 4096sort_buffer_size               = 2Mread_buffer_size               = 2Mread_rnd_buffer_size           = 2M# thread_concurrency             = 24join_buffer_size = 1M# table_cache = 32768thread_stack = 512kmax_length_for_sort_data = 16k# INNODB #innodb_flush_method            = O_DIRECTinnodb_log_buffer_size = 16Minnodb_flush_log_at_trx_commit = 2innodb_file_per_table          = 1innodb_buffer_pool_size        = 256M#innodb_buffer_pool_instances = 8innodb_stats_on_metadata = offinnodb_open_files = 8192innodb_read_io_threads = 16innodb_write_io_threads = 16innodb_io_capacity = 20000innodb_thread_concurrency = 0innodb_lock_wait_timeout = 60innodb_old_blocks_time=1000innodb_use_native_aio = 1innodb_purge_threads=1innodb_change_buffering=allinnodb_log_file_size = 64Minnodb_log_files_in_group = 2innodb_data_file_path  = ibdata1:256M:autoextendinnodb_rollback_on_timeout=on# LOGGING #log_error = /usr/local/mysql/sql_log/mysql-error.log# log_queries_not_using_indexes = 1# slow_query_log = 1slow_query_log_file = /usr/local/mysql/sql_log/slowlog.log# TimeOut ##interactive_timeout = 30#wait_timeout        = 30#net_read_timeout = 60[mysqldump]quickmax_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 = 16Msort_buffer_size = 5Mread_buffer = 2Mwrite_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服务重启
上一篇:CentOS安装配置VSFTP服务器
下一篇:谷歌Chrome浏览器内置谷歌翻译功能无法使用怎么办?(解决方法)