MySQL 5.7版本已经是一个非常稳定的成熟的版本,主要是针对5.7以下的版本进行常规的bug修复和性能优化,在安全性和性能方面进行了很多的改进,但是在一些高级功能方面不如8.0版本。而MySQL 8.0版本则是一个全新的版本,具有更多的新特性和性能改进,尤其是在高并发、数据库复杂查询、在线备份恢复等方面有很大的提升。
社区版本下载地址:
https://www.mysql.com → DOWNLOADS → MySQL Community (GPL) Downloads → MySQL Community Server
或直接访问:https://downloads.mysql.com/archives/community/
安装包选择:Compressed TAR Archive
解压
tar -zxvf mysql-8.0.32-el7-x86_64.tar.gz mv mysql-8.0.32-el7-x86_64 /usr/local/mysql-8.0.32
安装必要依赖
yum install -y libaio yum -y install numactl
创建data目录
mkdir -p /usr/local/mysql-8.0.32/data/
配置文件my.cnf(按8-16G情况时配置)
vi /etc/my.cnf
内容:
[client] #password = your_password port = 3306 socket = /tmp/mysql.sock [mysqld] binlog_cache_size = 192K thread_stack = 384K join_buffer_size = 2048K max_heap_table_size = 256M port = 3306 socket = /tmp/mysql.sock basedir = /usr/local/mysql-8.0.32 datadir = /usr/local/mysql-8.0.32/data default_storage_engine = InnoDB performance_schema_max_table_instances = 400 table_definition_cache = 400 skip-external-locking key_buffer_size = 256M max_allowed_packet = 100G table_open_cache = 1024 sort_buffer_size = 1024K net_buffer_length = 4K read_buffer_size = 2048K read_rnd_buffer_size = 1024K myisam_sort_buffer_size = 64M thread_cache_size = 192 tmp_table_size = 256M default_authentication_plugin = mysql_native_password lower_case_table_names = 1 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION explicit_defaults_for_timestamp = true #skip-name-resolve max_connections = 400 max_connect_errors = 100 open_files_limit = 65535 log-bin=mysql-bin binlog_format=mixed server-id = 1 binlog_expire_logs_seconds = 600000 slow_query_log=1 slow-query-log-file=/usr/local/mysql-8.0.32/data/mysql-slow.log long_query_time=3 #log_queries_not_using_indexes=on early-plugin-load = "" innodb_data_home_dir = /usr/local/mysql-8.0.32/data innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /usr/local/mysql-8.0.32/data innodb_buffer_pool_size = 512M innodb_log_file_size = 512M innodb_log_buffer_size = 128M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 4 innodb_write_io_threads = 4 [mysqldump] quick max_allowed_packet = 500M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 256M sort_buffer_size = 4M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout # bt_mysql_set = 4 # bt_mem_size = 4033.00 # bt_query_cache_size = 256
创建用户组和用户【必须】
groupadd mysql && useradd -r -g mysql mysql chown -R mysql:mysql /usr/local/mysql-8.0.32
执行初始化命令
cd /usr/local/mysql-8.0.32/bin ./mysqld --initialize --user=mysql --console
控制台打印初始化密码,例如
A temporary password is generated for root@localhost: yqjCzZoz.8h;
把启动脚本放到开机初始化目录
cp /usr/local/mysql-8.0.32/support-files/mysql.server /etc/init.d/mysql sudo systemctl enable mysql
将mysql登录命令创建软链接
ln -s /usr/local/mysql-8.0.32/bin/mysql /usr/bin/
使用service mysql start 命令启动
service mysql start
登录MySQL修改root用户默认密码并添加远程访问
登录MySQL:
mysql -uroot -p
修改密码:
alter user 'root'@'localhost' identified by 'Gtgj@2020'; flush privileges;
选择数据库:
use mysql;
修改mysql可被远程连接:
update user set host='%' where user='root'; flush privileges;
退出MySQL然后重启MySQL服务使修改的内容生效
exit; service mysql restart
【ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.】
vi /etc/my.cnf
在mysqld节点下增加内容
[mysqld] skip-grant-tables
重启service mysql restart,可无密码进入
修改为密码不过期
use mysql; update user set password_expired="N" where user="root"; flush privileges; quit;
重启MySQL即可。然后把my.cnf中mysqld节点刚才的配置注释,禁止无密码登录。
Java小强
未曾清贫难成人,不经打击老天真。
自古英雄出炼狱,从来富贵入凡尘。
发表评论: