
1、下载mysql8安装包linux 版本mysql-8.0.25-linux-glibc2.12-x86_64.tar2、创建文件夹 并进入到文件夹中文件夹名称随便取mkdir /env; cd env;3、上传mysql包可以使用linux 的rz命令上传如果找不到命令先安装下命令yum install -y lrzsz4、解压mysql包tar -xvf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz5、移动解压后的文件夹到/usr/local/mysqlmv mysql-8.0.25-linux-glibc2.12 /usr/local/mysql6、创建data文件夹一般用于存放数据库文件数据mkdir /usr/local/mysql/data7、创建用户组groupadd mysql; useradd -g mysql mysql;8、更改用户文件夹权限chown -R mysql.mysql /usr/local/mysql/9、生成my.cnf文件touch /etc/my.cnf10、编辑my.cnf[mysql] default-character-setutf8 [mysqld] port3306 default_authentication_pluginmysql_native_password socket /usr/local/mysql/mysql.sock basedir/usr/local/mysql datadir/usr/local/mysql/data/ character-set-serverutf8 default-storage-engineInnoDB collation-serverutf8_unicode_ci init_connectSET NAMES utf8 innodb_buffer_pool_size512M innodb_flush_log_at_trx_commit0 innodb_lock_wait_timeout31536000 innodb_log_buffer_size8M innodb_log_file_size16M join_buffer_size200M key_buffer_size400M log-error/usr/local/mysql/mysql.log pid-file/usr/local/mysql/mysql.pid log_error_verbosity1 max_allowed_packet2000M max_connections1000 max_heap_table_size6400M myisam_max_sort_file_size64M myisam_sort_buffer_size32M read_buffer_size4M read_rnd_buffer_size4000M server_id1 skip-external-lockingon sort_buffer_size256kb table_open_cache256 thread_cache_size16 tmp_table_size64M wait_timeout31536000 interactive_timeout31536000 sql_modeSTRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION group_concat_max_len10240 [client] port3306 default-character-setutf8 socket /usr/local/mysql/mysql.sockMac配置[mysql] default-character-setutf8 [mysqld] port3306 default_authentication_pluginmysql_native_password character-set-serverutf8 default-storage-engineInnoDB collation-serverutf8_unicode_ci innodb_buffer_pool_size512M innodb_flush_log_at_trx_commit0 innodb_lock_wait_timeout31536000 innodb_log_buffer_size8M innodb_log_file_size16M join_buffer_size200M key_buffer_size400M log_error_verbosity1 max_allowed_packet2000M max_connections1000 max_heap_table_size6400M myisam_max_sort_file_size64M myisam_sort_buffer_size32M read_buffer_size4M read_rnd_buffer_size4000M skip-external-lockingon sort_buffer_size256kb table_open_cache256 thread_cache_size16 tmp_table_size64M wait_timeout31536000 interactive_timeout31536000 sql_modeSTRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION group_concat_max_len10240 [client] port3306 default-character-setutf811、再次更改用户文件夹权限chown -R mysql:mysql /usr/local/mysql12、初始化数据库/usr/local/mysql/bin/mysqld --usermysql --initialize --basedir/usr/local/mysql --datadir/usr/local/mysql/data备注这里可能会报错 提示error while loading shared libraries: libaio.so.1: cannot open shared object file directory可以执行以下命令yum install libaio-devel.x86_6413、继续执行初始化数据库命令/usr/local/mysql/bin/mysqld --usermysql --initialize --basedir/usr/local/mysql --datadir/usr/local/mysql/data14、查看初始化密码 日志文件在 /usr/local/mysql/mysql.log15、修改配置挨个执行如果报错跳过cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod x /etc/init.d/mysqld chmod x /etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig --list mysqld16、修改环境变量并重载环境变量文件打开 /etc/profile 在底部添加如下命令export PATH$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib export PATH执行source /etc/profile17、启动mysqlservice mysql start18、登录mysql密码是上面的初始化密码mysql -uroot -p;19、第一次登录必须要先修改密码不然会提示ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.执行修改密码命令alter user rootlocalhost identified by 密码;20、授权远程访问update user set host% where userroot21、查看防火墙或者是组策略是否放行了3306端口