ubuntu 20.04安装mysql5.7

ubuntu20.04 安装mysql5.7 多实例

安装msyql5.7

添加源:

~# wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb

安装存储库:

在提示符下,选择 **Ubuntu **bionic,然后单击确定

下一个提示显示默认选择的MySQL 8.0。选择第一个选项,然后单击确定

在下一个提示中,选择 MySQL 5.7 服务器,然后单击确定

下一个提示默认选择MySQL5.7。选择最后一个 Ok,然后单击 OK

~# dpkg -i mysql-apt-config_0.8.12-1_all.deb

更新系统软件包:

~# apt update

如报错

  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD28
Reading package lists... Done
W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD28
E: The repository 'http://repo.mysql.com/apt/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

执行如下命令

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29

查看mysql5.7 包:

~# apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 8.0.26-0ubuntu0.20.04.2
  Version table:
     8.0.26-0ubuntu0.20.04.2 500
        500 http://mirrors.digitalocean.com/ubuntu focal-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages 
     8.0.19-0ubuntu5 500
        500 http://mirrors.digitalocean.com/ubuntu focal/main amd64 Packages
     5.7.35-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
Ubuntu 20.04 安装 MySQL 5.7
~# apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*

出现提示时输入并重新输入 root 密码

运行以下命令以保护MySQL(可选)

~# mysql_secure_installation

回车键。当系统提示输入密码时,请提供上面设置的 root 密码。设置用户的密码长度,用户登录账号权限

Enter current password for root (enter for none): 
VALIDATE PASSWORD PLUGIN can be used to test passwords 
and improve security. It checks the strength of password 
and allows the users to set only those passwords which are 
secure enough. Would you like to setup VALIDATE PASSWORD plugin? 

Press y|Y for Yes, any other key for No: Y 

There are three levels of password validation policy: 

LOW    Length >= 8 
MEDIUM Length >= 8, numeric, mixed case, and special characters 
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                 

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 
Using existing password for root. 
Estimated strength of the password: 25  
Change the password for root ? ((Press y|Y for Yes, any other key for No) : d
Remove anonymous users? [Y/n] Y 
Disallow root login remotely? [Y/n] Y 
Remove test database and access to it? [Y/n] Y 
Reload privilege tables now? [Y/n] Y 
Thanks for using MariaDB!

运行以下命令以显示版本

mysql> SELECT VERSION();
+-----------+ 
| VERSION() | 
+-----------+ 
| 5.7.35    | 
+-----------+ 
1 row in set (0.00 sec)

启用MySQL远程访问

~# vim /etc/mysql/mysql.conf.d/mysqld.cnf

查找行“bind_address”并更改如下:

# By default we only accept connections from localhost 
#bind-address   = 127.0.0.1 
bind-address   = 0.0.0.0

保持并重启mysql

~# systemctl restart mysql

要从远程计算机访问数据库,请运行以下命令:

~# mysql -u user -h database_server_ip -p

您已在 Ubuntu 20.04 上成功安装了 MySQL 5.7。

安装mysql5.7多实例

创建多实例数据库目录

~# mkdir -p /home/data/mysql/3307/{binlog,data,galera,log,tmp}
~# chown mysql. -R /home/data/mysql
~# vim my.cnf
[mysqld]
bind-address=0.0.0.0
port=3307
default_storage_engine=innodb
character-set-server=utf8
skip-name-resolve
server-id=1
open_files_limit=16384
lock_wait_timeout=300
#sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql_mode=NO_ENGINE_SUBSTITUTION
#目录
datadir=/data/mysql/3307/data
socket=/data/mysql/3307/mysql.sock
pid-file=/data/mysql/3307/mysql.pid
tmpdir=/data/mysql/3307/tmp
user=mysql
#最大连接数
max_connections=16384
#缓存块大小
max_allowed_packet=100M
#slow log
slow-query-log=1
slow_query_log_file=/data/mysql/3307/log/slow.log
long_query_time=5
log-queries-not-using-indexes=1
#binlog
log-slave-updates=true
binlog_format=ROW
expire_logs_days=5
relay-log=mysqld-relay-bin
log-bin=/data/mysql/3307/binlog/binlog
log-bin-index=/data/mysql/3307/binlog/binlog.index
#error logs
log-error=/data/mysql/3307/log/error.log
sync_binlog=0
#自增主键预留值
innodb_autoinc_lock_mode=2
#写日志频率 0系统自动 1同时记录 2每秒写一次
innodb_flush_log_at_trx_commit=0
#innodb的索引、数据及缓存占内存的大小
innodb_buffer_pool_size=122M
#双写  增加数据安全性
innodb_doublewrite=1
#间隙锁
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0

初始化数据库(AppArmor 禁用mysql)

~# mysqld --defaults-file=/data/mysql/3307/3307.cnf --initialize

启动数据库

~# mysqld --defaults-file=/data/mysql/3307/my.cnf &

加入开机启动

~# echo "mysqld --defaults-file=/data/mysql/3307/my.cnf &" >> /etc/rc.local
配置AppArmor

Ubuntu 操作系统附带 AppArmor,这是一个 Linux 内核安全模块,允许系统管理员通过每个程序配置文件来限制程序的功能。 配置文件可以允许网络访问、原始套接字访问以及在匹配路径上读取、写入或执行文件的权限。 Rhel 家族用户会注意到这与 Selinux 类似; 然而,它们的工作方式不同,各有利弊。

  • 如何为特定进程禁用 AppArmor
  • 如何完全禁用AppArmor

首先检查 Ubuntu 20.04 系统上 AppArmor 的当前状态:

~# apparmor_status

仅对特定进程禁用 AppArmor,请首先列出所有可用的配置文件:

~# ls /etc/apparmor.d/
abstractions    lsb_release      usr.bin.evince                        usr.lib.libreoffice.program.senddoc      usr.sbin.cups-browsed  usr.sbin.rsyslogd
disable         nvidia_modprobe  usr.bin.firefox                       usr.lib.libreoffice.program.soffice.bin  usr.sbin.cupsd         usr.sbin.tcpdump
force-complain  sbin.dhclient    usr.bin.man                           usr.lib.libreoffice.program.xpdfimport   usr.sbin.ippusbxd
local           tunables         usr.lib.libreoffice.program.oosplash  usr.lib.snapd.snap-confine.real          usr.sbin.mysqld

例如,我们现在将为MySQL服务器禁用AppArmor:

~# ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
~# apparmor_parser -R /etc/apparmor.d/disable/usr.sbin.mysqld

要完全禁用 AppArmor,请执行:

~# systemctl disable apparmor

最后重启服务

~# systemctl restart apparmor.service

你可能感兴趣的:(ubuntu 20.04安装mysql5.7)