CentOS 7.7下MySQL 8安装和配置

文章目录

  • CentOS 7.7下MySQL 8安装和配置
    • MySQL 8安装包百度云下载地址
    • 检查操作系统是否具备运行环境
    • MySQL 8安装和配置
      • 解压安装包
      • 将解压后的安装包移动到指定目录
      • 创建相关用户、用户组、目录、授权
        • 创建用户组和用户
        • 创建MySQL数据目录以及授权
      • 创建MySQL配置文件
      • 初始化MySQL
      • 设置启动文件和环境变量
        • 设置启动文件
        • 设置环境变量
      • 登陆MySQL
        • 启动MySQL
        • 初次登陆MySQL
        • 再次登陆MySQL
      • 设置MySQL远程登陆
        • 更新用户host
        • 将MySQL端口加入防火墙白名单
          • 检查防火墙状态
          • 将MySQL端口加入防火墙白名单
      • MySQL设置开机启动
          • 赋予MySQL启动脚本可执行权限
          • 添加mysql服务
          • 重启系统后查看MySQL是否已经自动启动
      • MySQL相关命令
        • 启动MySQL
        • 关闭MySQL
        • 重启MySQL
        • 查看MySQL状态

CentOS 7.7下MySQL 8安装和配置

安装包:mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

操作系统:CentOS Linux release 7.7.1908 (Core)

运行环境:gcc-c+±4.8.5-39.el7.x86_64

MySQL 8安装包百度云下载地址

链接:https://pan.baidu.com/s/1SpVw1yMecM8fDij6YkeDoA  密码:f1fj


检查操作系统是否具备运行环境

[root@localhost root]# rpm -qa | grep gcc
libgcc-4.8.5-39.el7.x86_64
gcc-4.8.5-39.el7.x86_64
gcc-c++-4.8.5-39.el7.x86_64
gcc-gfortran-4.8.5-39.el7.x86_64


  • 如果不具备该运行环境,请查阅安装gcc-c++运行环境

MySQL 8安装和配置

解压安装包

[root@localhost root]# tar xJvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 
mysql-8.0.18-linux-glibc2.12-x86_64/bin/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.18-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.18-linux-glibc2.12-x86_64/bin/myisamlog
mysql-8.0.18-linux-glibc2.12-x86_64/bin/myisampack
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysql
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysql_config_editor
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysql_secure_installation
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysql_ssl_rsa_setup
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysql_tzinfo_to_sql
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysql_upgrade
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqladmin
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlbinlog
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlcheck
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqldump
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlimport
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlpump
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlrouter_keyring
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlshow
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlslap
mysql-8.0.18-linux-glibc2.12-x86_64/bin/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld-debug
mysql-8.0.18-linux-glibc2.12-x86_64/bin/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysql_config
mysql-8.0.18-linux-glibc2.12-x86_64/include/
mysql-8.0.18-linux-glibc2.12-x86_64/include/errmsg.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/field_types.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/my_command.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/my_compress.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/my_list.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql/
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql/client_plugin.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql/plugin_auth_common.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql/udf_registration_types.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql_com.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql_time.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysql_version.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysqld_error.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysqlx_ername.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysqlx_error.h
mysql-8.0.18-linux-glibc2.12-x86_64/include/mysqlx_version.h
mysql-8.0.18-linux-glibc2.12-x86_64/lib/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlclient.a
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlservices.a
mysql-8.0.18-linux-glibc2.12-x86_64/lib/pkgconfig/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/pkgconfig/mysqlclient.pc
mysql-8.0.18-linux-glibc2.12-x86_64/share/
mysql-8.0.18-linux-glibc2.12-x86_64/share/aclocal/
mysql-8.0.18-linux-glibc2.12-x86_64/share/aclocal/mysql.m4
mysql-8.0.18-linux-glibc2.12-x86_64/docs/
mysql-8.0.18-linux-glibc2.12-x86_64/docs/ChangeLog
mysql-8.0.18-linux-glibc2.12-x86_64/docs/INFO_SRC
mysql-8.0.18-linux-glibc2.12-x86_64/docs/
mysql-8.0.18-linux-glibc2.12-x86_64/docs/INFO_BIN
mysql-8.0.18-linux-glibc2.12-x86_64/docs/INFO_SRC
mysql-8.0.18-linux-glibc2.12-x86_64/man/
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/comp_err.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/ibd2sdi.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/innochecksum.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/lz4_decompress.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/my_print_defaults.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/myisam_ftdump.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/myisamchk.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/myisamlog.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/myisampack.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql.server.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql_config.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql_config_editor.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql_secure_installation.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql_ssl_rsa_setup.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql_tzinfo_to_sql.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysql_upgrade.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqladmin.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlbinlog.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlcheck.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqld_multi.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqld_safe.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqldump.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqldumpslow.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlimport.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlman.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlpump.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlrouter.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlrouter_passwd.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlrouter_plugin_info.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlshow.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/mysqlslap.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/perror.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man1/zlib_decompress.1
mysql-8.0.18-linux-glibc2.12-x86_64/man/man8/
mysql-8.0.18-linux-glibc2.12-x86_64/man/man8/mysqld.8
mysql-8.0.18-linux-glibc2.12-x86_64/LICENSE
mysql-8.0.18-linux-glibc2.12-x86_64/README
mysql-8.0.18-linux-glibc2.12-x86_64/LICENSE.router
mysql-8.0.18-linux-glibc2.12-x86_64/README.router
mysql-8.0.18-linux-glibc2.12-x86_64/bin/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlrouter
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlrouter_passwd
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqlrouter_plugin_info
mysql-8.0.18-linux-glibc2.12-x86_64/docs/
mysql-8.0.18-linux-glibc2.12-x86_64/docs/sample_mysqlrouter.conf
mysql-8.0.18-linux-glibc2.12-x86_64/lib/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlharness.a
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlharness.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlharness.so.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlrouter.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlrouter.so.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlrouter_http.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlrouter_http.so.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/http_auth_backend.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/http_auth_realm.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/http_server.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/keepalive.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/libprotobuf-lite.so.3.6.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/metadata_cache.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/mysql_protocol.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/rest_api.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/rest_metadata_cache.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/rest_router.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/rest_routing.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mysqlrouter/routing.so
mysql-8.0.18-linux-glibc2.12-x86_64/run/
mysql-8.0.18-linux-glibc2.12-x86_64/var/
mysql-8.0.18-linux-glibc2.12-x86_64/var/lib/
mysql-8.0.18-linux-glibc2.12-x86_64/var/lib/mysqlrouter/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/ibd2sdi
mysql-8.0.18-linux-glibc2.12-x86_64/bin/innochecksum
mysql-8.0.18-linux-glibc2.12-x86_64/bin/lz4_decompress
mysql-8.0.18-linux-glibc2.12-x86_64/bin/my_print_defaults
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld_multi
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqld_safe
mysql-8.0.18-linux-glibc2.12-x86_64/bin/mysqldumpslow
mysql-8.0.18-linux-glibc2.12-x86_64/bin/perror
mysql-8.0.18-linux-glibc2.12-x86_64/bin/zlib_decompress
mysql-8.0.18-linux-glibc2.12-x86_64/lib/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/char.bin
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/dicrc
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/left-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/matrix.bin
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/pos-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/rewrite.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/right-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/sys.dic
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_euc-jp/unk.dic
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/char.bin
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/dicrc
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/left-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/matrix.bin
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/pos-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/rewrite.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/right-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/sys.dic
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_sjis/unk.dic
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/char.bin
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/dicrc
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/left-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/matrix.bin
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/pos-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/rewrite.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/right-id.def
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/sys.dic
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/dic/ipadic_utf-8/unk.dic
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/etc/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/mecab/etc/mecabrc
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/adt_null.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/auth_socket.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/authentication_ldap_sasl_client.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/component_audit_api_message_emit.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/component_log_filter_dragnet.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/component_log_sink_json.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/component_log_sink_syseventlog.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/component_mysqlbackup.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/component_validate_password.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/connection_control.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/ddl_rewriter.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/adt_null.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/auth_socket.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/authentication_ldap_sasl_client.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/component_audit_api_message_emit.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/component_log_filter_dragnet.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/component_log_sink_json.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/component_log_sink_syseventlog.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/component_mysqlbackup.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/component_validate_password.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/connection_control.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/ddl_rewriter.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/group_replication.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/ha_example.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/ha_mock.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/innodb_engine.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/keyring_file.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/keyring_udf.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/libmemcached.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/libpluginmecab.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/locking_service.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/mypluglib.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/mysql_clone.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/mysql_no_login.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/rewrite_example.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/rewriter.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/semisync_master.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/semisync_slave.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/validate_password.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/version_token.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/group_replication.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/ha_example.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/ha_mock.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/innodb_engine.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/keyring_file.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/keyring_udf.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/libmemcached.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/libpluginmecab.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/locking_service.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/mypluglib.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/mysql_clone.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/mysql_no_login.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/rewrite_example.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/rewriter.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/semisync_master.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/semisync_slave.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/validate_password.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/version_token.so
mysql-8.0.18-linux-glibc2.12-x86_64/share/
mysql-8.0.18-linux-glibc2.12-x86_64/share/bulgarian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/bulgarian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/Index.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/README
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/armscii8.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/ascii.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/cp1250.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/cp1251.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/cp1256.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/cp1257.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/cp850.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/cp852.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/cp866.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/dec8.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/geostd8.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/greek.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/hebrew.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/hp8.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/keybcs2.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/koi8r.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/koi8u.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/latin1.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/latin2.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/latin5.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/latin7.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/macce.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/macroman.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/charsets/swe7.xml
mysql-8.0.18-linux-glibc2.12-x86_64/share/czech/
mysql-8.0.18-linux-glibc2.12-x86_64/share/czech/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/danish/
mysql-8.0.18-linux-glibc2.12-x86_64/share/danish/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/dictionary.txt
mysql-8.0.18-linux-glibc2.12-x86_64/share/dutch/
mysql-8.0.18-linux-glibc2.12-x86_64/share/dutch/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/english/
mysql-8.0.18-linux-glibc2.12-x86_64/share/english/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/errmsg-utf8.txt
mysql-8.0.18-linux-glibc2.12-x86_64/share/estonian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/estonian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/french/
mysql-8.0.18-linux-glibc2.12-x86_64/share/french/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/german/
mysql-8.0.18-linux-glibc2.12-x86_64/share/german/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/greek/
mysql-8.0.18-linux-glibc2.12-x86_64/share/greek/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/hungarian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/hungarian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/innodb_memcached_config.sql
mysql-8.0.18-linux-glibc2.12-x86_64/share/italian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/italian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/japanese/
mysql-8.0.18-linux-glibc2.12-x86_64/share/japanese/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/korean/
mysql-8.0.18-linux-glibc2.12-x86_64/share/korean/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/norwegian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/norwegian-ny/
mysql-8.0.18-linux-glibc2.12-x86_64/share/norwegian-ny/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/norwegian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/polish/
mysql-8.0.18-linux-glibc2.12-x86_64/share/polish/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/portuguese/
mysql-8.0.18-linux-glibc2.12-x86_64/share/portuguese/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/romanian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/romanian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/russian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/russian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/serbian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/serbian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/slovak/
mysql-8.0.18-linux-glibc2.12-x86_64/share/slovak/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/spanish/
mysql-8.0.18-linux-glibc2.12-x86_64/share/spanish/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/swedish/
mysql-8.0.18-linux-glibc2.12-x86_64/share/swedish/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/share/ukrainian/
mysql-8.0.18-linux-glibc2.12-x86_64/share/ukrainian/errmsg.sys
mysql-8.0.18-linux-glibc2.12-x86_64/support-files/
mysql-8.0.18-linux-glibc2.12-x86_64/support-files/mysql-log-rotate
mysql-8.0.18-linux-glibc2.12-x86_64/support-files/mysql.server
mysql-8.0.18-linux-glibc2.12-x86_64/support-files/mysqld_multi.server
mysql-8.0.18-linux-glibc2.12-x86_64/bin/
mysql-8.0.18-linux-glibc2.12-x86_64/bin/libcrypto.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/bin/libssl.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libcrypto.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libcrypto.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlclient.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlclient.so.21
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libmysqlclient.so.21.1.18
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libssl.so
mysql-8.0.18-linux-glibc2.12-x86_64/lib/libssl.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/libcrypto.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/debug/libssl.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/libcrypto.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/plugin/libssl.so.1.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/private/
mysql-8.0.18-linux-glibc2.12-x86_64/lib/private/libprotobuf-lite.so.3.6.1
mysql-8.0.18-linux-glibc2.12-x86_64/lib/private/libprotobuf.so.3.6.1
mysql-8.0.18-linux-glibc2.12-x86_64/share/
mysql-8.0.18-linux-glibc2.12-x86_64/share/install_rewriter.sql
mysql-8.0.18-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql


将解压后的安装包移动到指定目录

[root@localhost root]# mv mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost root]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  LICENSE.router  man  README  README.router  run  share  support-files  var


创建相关用户、用户组、目录、授权

创建用户组和用户

# 创建mysql用户组
[root@localhost mysql]# groupadd mysql

# 创建mysql用户
[root@localhost mysql]# useradd mysql
useradd:mysql 组已经存在 - 如果您想将此用户加入到该组,请使用 -g 参数。

# 将mysql用户加入mysql用户组
[root@localhost mysql]# useradd -g mysql mysql


创建MySQL数据目录以及授权

[root@localhost mysql]# mkdir -p /data/mysql
[root@localhost mysql]# chown -R mysql:mysql /data/mysql/
[root@localhost mysql]# chmod -R 777 /data/mysql/


创建MySQL配置文件

[root@localhost mysql]# vim /etc/my.cnf


  • 配置文件内容如下:

    [mysqld]
    server-id                      = 1
    port                           = 3306
    mysqlx_port                    = 33060
    mysqlx_socket                  = /tmp/mysqlx.sock
    datadir                        = /data/mysql
    socket                         = /tmp/mysql.sock
    pid-file                       = /tmp/mysqld.pid
    log-error                      = error.log
    slow-query-log                 = 1
    slow-query-log-file            = slow.log
    long_query_time                = 0.2
    log-bin                        = bin.log
    relay-log                      = relay.log
    binlog_format                  = ROW
    relay_log_recovery             = 1
    character-set-client-handshake = FALSE
    character-set-server           = utf8mb4
    collation-server               = utf8mb4_unicode_ci
    init_connect                   = 'SET NAMES utf8mb4'
    innodb_buffer_pool_size        = 1G
    join_buffer_size               = 128M
    sort_buffer_size               = 2M
    read_rnd_buffer_size           = 2M
    log_timestamps                 = SYSTEM
    lower_case_table_names         = 1
    default-authentication-plugin  = mysql_native_password
    sql_mode                       = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
    
    
    

初始化MySQL

[root@localhost mysql]# /usr/local/mysql/bin/mysqld --user=mysql -basedir=/usr/local/mysql --datadir=/data/mysql --initialize


  • 在初始化MySQL之后,在错误日志中会生成初始密码

    # 这里的初始密码为b+mfpSFsg68k,后面在第一次登陆MySQL的时候要用到
    [root@localhost mysql]# cat /data/mysql/error.log | grep -i password
    2020-04-18T16:20:37.145223+08:00 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: b+mfpSFsg68k
    
    
    

设置启动文件和环境变量

设置启动文件

[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql


设置环境变量

[root@localhost mysql]# vim /etc/profile.d/mysql.sh
[root@localhost mysql]# source /etc/profile.d/mysql.sh 
[root@localhost mysql]# mysqld --version
/usr/local/mysql/bin/mysqld  Ver 8.0.18 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)


  • mysql.sh文件内容如下

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

登陆MySQL

启动MySQL

[root@localhost mysql]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS! 


初次登陆MySQL

[root@localhost mysql]# /usr/local/mysql/bin/mysql -p -S /tmp/mysql.sock
# 输入错误日志文件中的初始密码
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.18

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# 修改root用户密码
mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.01 sec)

# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

# 查看mysql版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.18    |
+-----------+
1 row in set (0.00 sec)

mysql> exit
Bye


再次登陆MySQL

[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye


设置MySQL远程登陆

更新用户host

[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
# 允许root用户从任何IP地址的机器登陆到MySQL
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye


将MySQL端口加入防火墙白名单

检查防火墙状态
[root@localhost mysql]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 六 2020-04-18 15:32:30 CST; 57min ago
     Docs: man:firewalld(1)
 Main PID: 959 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─959 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

4月 18 15:32:29 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
4月 18 15:32:30 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.


  • 此时的防火墙是开启的,如果MySQL端口(默认是3306)没有加入防火墙白名单,那么远程登陆MySQL将失败
将MySQL端口加入防火墙白名单
# 设置3306端口的udp协议允许通过防火墙
[root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/udp --permanent
success

# 设置3306端口的tcp协议允许通过防火墙
[root@localhost mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success

# 重启防火墙
[root@localhost mysql]# systemctl restart firewalld.service

# 查看3306端口是否成功添加到防火墙白名单中
[root@localhost mysql]# firewall-cmd --zone=public --list-ports
3306/udp 3306/tcp


MySQL设置开机启动

赋予MySQL启动脚本可执行权限
# 这里的/etc/init.d/mysql脚本文件的内容是mysq自带的,来源于/usr/local/mysql/support-files/mysql.server 
[root@localhost ~]# chmod +x /etc/init.d/mysql 


添加mysql服务
[root@localhost ~]# chkconfig --add mysql


重启系统后查看MySQL是否已经自动启动
[root@localhost ~]# ps -ef | grep mysql
root       1353      1  0 11:05 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/tmp/mysqld.pid
mysql      2324   1353  6 11:05 ?        00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=error.log --pid-file=/tmp/mysqld.pid --socket=/tmp/mysql.sock --port=3306
root       3125   2777  0 11:06 pts/0    00:00:00 grep --color=auto mysql
[root@localhost ~]# netstat -nltp | grep mysql
tcp6       0      0 :::33060                :::*                    LISTEN      2324/mysqld         
tcp6       0      0 :::3306                 :::*                    LISTEN      2324/mysqld 


  • 可以看到MySQL相关进程和端口已经正常,说明开机启动设置成功

MySQL相关命令

启动MySQL

[root@localhost ~]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS! 

[root@localhost ~]# systemctl start mysql.service 


关闭MySQL

[root@localhost ~]# /etc/init.d/mysql stop
Shutting down MySQL... SUCCESS! 

[root@localhost ~]# systemctl stop mysql.service 


重启MySQL

[root@localhost ~]# /etc/init.d/mysql restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 

[root@localhost ~]# systemctl restart mysql.service 


查看MySQL状态

[root@localhost ~]# /etc/init.d/mysql status
 SUCCESS! MySQL running (2324)

[root@localhost ~]# systemctl status mysql.service 
● mysql.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysql; bad; vendor preset: disabled)
   Active: active (exited) since 日 2020-04-19 11:05:59 CST; 3min 31s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1317 ExecStart=/etc/rc.d/init.d/mysql start (code=exited, status=0/SUCCESS)

4月 19 11:05:51 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
4月 19 11:05:59 localhost.localdomain mysql[1317]: Starting MySQL....... SUCCESS!
4月 19 11:05:59 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.


你可能感兴趣的:(软件安装配置)