1.下载mysql
第一步:下载mysql安装包,也可以通过本地xftp上传到虚拟机 mysq
- 国内镜像地址:http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/
- mysql官网地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
- 博主提供地址
链接:https://pan.baidu.com/s/1RbdQk-hucvRdbVIbxDHbRA?pwd=6tkk 提取码:6tkk
>
> cd /usr/local
>
> wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.19- linux-glibc2.12-x86_64.tar.xz
第二步:将下载的mysql安装包解压
tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz mysql
groupadd mysql
useradd -r -g mysql mysql
第三步:配置mysql配置文件与初始化mysql
chown -R mysql:mysql /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql -- datadir=/usr/local/mysql/data
chown -R root:root /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data
chmod 755 /etc/my.cnf
以下是配置文件内容:
[mysql]
default-character-set=utf8
[client]
port=3306
default-character-set=utf8
socket=/usr/local/mysql/tmp/mysql.sock
[mysqld]
socket=/usr/local/mysql/tmp/mysql.sock
port=3306
default_authentication_plugin=mysql_native_password
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
character-set-server=utf8
default-storage-engine=InnoDb
max_connections=1000
collation-server=utf8_unicode_ci
init_connect='SET NAMES utf8'
innodb_buffer_pool_size=64M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=120
innodb_log_buffer_size=4M
innodb_log_file_size=256M
interactive_timeout=120
join_buffer_size=2M
key_buffer_size=32M
log-error=/usr/local/mysql/data/data.err
log_error_verbosity=1
max_allowed_packet=256M
max_heap_table_size=64M
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=32M
read_buffer_size=512kb
read_rnd_buffer_size=4M
log_bin=mysql-bin
server-id=1
skip-external-locking=on
sort_buffer_size=256kb
table_open_cache=256
thread_cache_size=16
tmp_table_size=64M
wait_timeout=2288800
general_log=ON
general_log_file=/usr/local/mysql/data/query_log.pid
slow_query_log=ON
slow_query_log_file=sql-slow.log
long_query_time=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
创建mysql.sock存储文件tmp
mkdir tmp
chmod 777 tmp
第四步:加入开机自启
cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list mysql
第五步:开启mysql服务并配置环境变量
service mysql start
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
source /etc/profile
第六步:登录mysql,修改密码
mysql -uroot -p
--修改密码
alter user 'root'@'localhost' identified by 'root';
|