Install mysql8
CentOS Install mysql8
官网 mysql
第一步 安装 mysql8
# 创建目录mkdir -p /usr/local/softwares/packages && cd /usr/local/softwares/packages# 查看 glibc版本ldd --version# 下载wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.34-linux-glibc2.28-x86_64.tar.gz# 解压tar -xf mysql-8.0.34-linux-glibc2.28-x86_64.tar.gz# 移动到安装软件目录mv mysql-8.0.34-linux-glibc2.28-x86_64 /usr/local/mysql# 查看版本号/usr/local/mysql/bin/mysql --version
第二步 配置环境变量
# 修改文件vim /etc/profile# mysqlexport MYSQL_HOME=/usr/local/mysqlexport PATH=$PATH:$MYSQL_HOME/bin# 重载source /etc/profile
第三步 创建用户组和用户
# 创建用户组和用户groupadd mysqluseradd -g mysql mysql# 赋予权限chown -R mysql.mysql /usr/local/mysql/
第四步 设置开机启动
# 创建文件cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql# 添加到服务列表chkconfig --add mysql# 查看服务列表chkconfig --listchkconfig mysql on
第五步 创建配置文件
vim /etc/my.cnf
[mysql]# 默认字符集default-character-set=utf8mb4[client]port=3306socket=/tmp/mysql.sock[mysqld]port=3306server-id=3306user=mysqlsocket=/tmp/mysql.sock# 安装目录basedir=/usr/local/mysql# 数据存放目录datadir=/usr/local/mysql/datalog-bin=/usr/local/mysql/data/mysql-bininnodb_data_home_dir=/usr/local/mysql/datainnodb_log_group_home_dir=/usr/local/mysql/data# 日志及进程数据的存放目录log-error=/usr/local/mysql/data/mysql.logpid-file=/usr/local/mysql/data/mysql.pid# 服务端字符集character-set-server=utf8mb4lower_case_table_names=1autocommit=1#####以上涉及的文件夹,注意修改skip-external-lockingkey_buffer_size=256Mmax_allowed_packet=1Mtable_open_cache=1024sort_buffer_size=4Mnet_buffer_length=8Kread_buffer_size=4Mread_rnd_buffer_size=512Kmyisam_sort_buffer_size=64Mthread_cache_size=128# query_cache_size=128Mtmp_table_size=128Mexplicit_defaults_for_timestamp=truemax_connections=500max_connect_errors=100open_files_limit=65535binlog_format=mixedbinlog_expire_logs_seconds=864000# 创建表时使用的默认存储引擎default_storage_engine=InnoDBinnodb_data_file_path=ibdata1:10M:autoextendinnodb_buffer_pool_size=1024Minnodb_log_file_size=256Minnodb_log_buffer_size=8Minnodb_flush_log_at_trx_commit=1innodb_lock_wait_timeout=50transaction-isolation=READ-COMMITTED[mysqldump]quickmax_allowed_packet=16M[myisamchk]key_buffer_size=256Msort_buffer_size=4Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout
第六步 启动
# 初始化mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --initialize-insecure# 启动service mysql start# 查看状态service mysql status
第七步 设置密码
# 无密码登录(直接回车)mysql -u root -p# 设置密码alter user 'root'@'localhost' identified by 'password';# 刷新权限flush privileges;# 退出exit
第八步 创建远程root用户
# 登录mysql -u root -p;# 创建用户CREATE user 'root'@'%';# 设置密码alter user 'root'@'%' identified by 'newpassword';# 授权用户所有权限GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';# 刷新权限FLUSH PRIVILEGES;# 查看所有用户状态select user,host,plugin,authentication_string from mysql.user;