一、下载安装包
https://dev.mysql.com/downloads/file/
可以用ftp上传到linux上
二、解压文件
tar xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
注意:(z)参数我在添加的时候出现问题
三、添加系统mysql组和mysql用户:
groupadd mysql
useradd -g mysql mysql
四、将解压后的文件移动到安装目录 并重命名
mv mysql-8.0.16-linux-glibc2.12-x86_64 /usr/local/mysql
五、将mysql目录的所有者更换为mysql用户
chown -R mysql:mysql /usr/local/mysql
六、创建配置文件相关目录
mkdir -p {data,binlogs,log,etc,run}
七、修改配置目录的权限
chown -R mysql:mysql ./{data,binlogs,log,etc,run}
八、编写配置文件
注意:query_cache_type = 0 query_cache_size = 0 将这两行注释掉,此配置文件不是精确,请自行选择
vim /usr/local/mysql/etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535
skip-name-resolve
lower_case_table_names=1
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 2048M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
key_buffer_size = 64M
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/binlogs/mysql-bin
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 0
query_cache_size = 0
server-id=1
九、初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
注意:此处如果安装 出错
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
原因事linux没有 缺少安装包libaio和libaio-devel.
解决方法执行 yum install -y libaio 命令
此时会在控制台打印
记住密码。假如没有人任何提示查看在日志文件里会提示一个临时密码,记录这个密码
grep 'temporary password' /usr/local/mysql/log/mysql_error.log
如果控制台或者mysql_error.log 出现了 unknown variable 'query_cache_type=0'的错误,将my.cnf 的query_cache_*都注释掉(我是第一次安装没出现这个问题,第二次出现这个问题),个人猜想 原因是升级的mysql中没有这两个配置,我的配置文件拷贝的是5点多的
十、设置启动文件和环境变量
将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限,这样就可以使用service mysql命令启动/停止服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
注册启动服务:
chkconfig --add mysql
查看是否添加成功
chkconfig --list
显示:mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
环境变量:
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
十一、启动mysql数据库
systemctl start mysql
systemctl stop mysql
systemctl restart mysql
十二、登录修改密码
mysql -uroot -p cCS<-H=Yu0Os //后面是系统生成的密码
出现问题:
Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决方案:
- systemctl stop mysql
- mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
- mysql
- use mysql
- CREATE USER 'root'@'%' IDENTIFIED BY '你的密码';(这步出错请执行FLUSH PRIVILEGES;在执行4)
- GRANT ALL ON *.* TO 'root'@'%';
- ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
- ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
- FLUSH PRIVILEGES;
- quitexitquit
重启后可以正常登录了
十三、远程连接
防火墙开通3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 对外开放3306端口,供外部的计算机访问
# 该命令方式添加的端口,可在/etc/firewalld/zones中的对应配置文件中得到体现
systemctl restart firewalld
# 重启防火墙
查看防火墙规则
firewall-cmd --list-all
做完上述操作后你会发现,你远程连接不上。
1. 问题描述: 2. 出现该问题的过程 3. 解决思路 中有一段话: 3.查看3306端口运行的进程 lsof -i :3306test:~ # lsof -i :3306COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEmysqld 4620 mysql 12u IPv4 10559 0t0 TCP *:mysql (LISTEN) 其实使用“ps aux|grep mysql”命令在查看mysql服务时,也能看到参数skip-networking: 所以现在所要做的就是将参数skip-networking关闭掉。 4. 解决问题
|
按照上述操作之后远程登陆成功,到此,安装成功。