准备工作
Labs
1 2 3 4 5 6 7 |
git clone https://github.com/pboros/mysql8_administration_labs.git # 相关命令 vagrant status vagrant up vagrant ssh vagrant halt vagrant destroy -f |
若因下载box时间过长,可通过迅雷下载:https://vagrantcloud.com/centos/boxes/7/versions/1801.02/providers/virtualbox.box,然后添加本地 box:
1 |
vagrant box add centos/7 ~/Downloads/virtualbox.box |
注:若版本不一致,请修改Vagrantfile中的lab1a.vm.box_version
安装
使用RPM 包安装 MySQL 8(CentOS7)
查找 rpm 包:https://dev.mysql.com/downloads/repo/yum/
1 2 3 4 5 6 7 8 9 10 11 12 13 |
curl -L -O https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm sudo yum localinstall -y mysql80-community-release-el7-2.noarch.rpm sudo yum repolist enabled | grep "mysql.*-community.*" sudo yum install -y mysql-community-server sudo systemctl start mysqld sudo grep password /var/log/mysqld.log #其它相关命令 sudo yum repolist all | grep mysql sudo yum-config-manager --disable mysql57-community sudo yum-config-manager --enable mysql80-community sudo yum repolist enabled | grep mysql ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; |
使用DEB 包安装 MySQL 8(Ubuntu 16.04)
查找 deb 包:https://dev.mysql.com/downloads/repo/apt/
1 2 3 4 5 6 7 |
curl -L -O https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb # 选择 ok sudo apt-get -y update sudo apt-get install -y mysql-community-server sudo systemctl start mysql.service # 安装后启动服务错误请执行sudo /usr/sbin/mysqld后再行尝试 # 若安装过程中所设置密码无法登录,请不填密码直接登录,使用 ALTER USER 语句设置密码 |
使用二进制 Tarball 安装 MySQL 8(以 CentOS 7为例)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
sudo yum remove -y mariadb-libs curl -L -O https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz sudo tar -xvf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz -C /usr/local/ sudo yum -y install libaio sudo groupadd mysql sudo useradd -r -g mysql -s /bin/false mysql getent passwd | grep mysql # 查看用户创建是否成功 cd /usr/local sudo ln -s mysql-8.0.15-linux-glibc2.12-x86_64 mysql sudo mkdir mysql-files sudo chown mysql:mysql mysql-files sudo chmod 750 mysql-files cd mysql sudo ./bin/mysqld --initialize --user=mysql # 此处会生成临时密码,MySQL 8取消了早期版本的mysql_install_db, 使用mysqld --initialize sudo cp ./support-files/mysql.server /etc/init.d/ sudo /etc/init.d/mysql.server start ./bin/mysql -uroot -p # 使用 ALTER USER 语句修改密码 |
配置MySQL(/etc/my.cnf)
配置文件分区显示,分区可进行混配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[mysqld] server_option1 = value1 server_option2 = value2 !include /path/to/file !includedir /etc/conf.d [client] client_option3 = value3 # 配置 user 和 password 后则在操作时无需输入用户名密码 user = root password = MyNewPass4! [mysqldump] client_option4 = value4 [mysqld] server_option5 = value5 server_option2 = value6 #可进行值的覆盖 |