Linux 安装 解压版 mysql 8.0.12

一、下载安装包 

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)

解决方案:

  1. systemctl stop mysql
  2. mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
  3. mysql
  4. use mysql
  5. CREATE USER 'root'@'%' IDENTIFIED BY '你的密码';(这步出错请执行FLUSH PRIVILEGES;在执行4)
  6. GRANT ALL ON *.* TO 'root'@'%';
  7. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
  8. ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
  9. FLUSH PRIVILEGES;
  10. quitexitquit

重启后可以正常登录了

十三、远程连接

防火墙开通3306端口

firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 对外开放3306端口,供外部的计算机访问
# 该命令方式添加的端口,可在/etc/firewalld/zones中的对应配置文件中得到体现

systemctl restart firewalld
# 重启防火墙

查看防火墙规则

firewall-cmd --list-all 

 

做完上述操作后你会发现,你远程连接不上。

1. 问题描述:
        (1)本地“mysql -u -p”可以连接mysql数据库,但是“mysql -uroot -h127.0.0.1 -p” 和 “mysql -uroot -p192.168.0.161 -p”均无法登录mysql数据库;
        (2)远程连接mysql服务连接不上,并且 “telnet 192.168.0.161 3306”不通;
        (3)使用“ps aux|grep mysql”查看mysal服务,服务是存在的;
        (4)使用命令:netstat -talnp
         lsof -i :3306
        均查看不到3306端口上的监听;

2. 出现该问题的过程
        在Linux下安装mysq数据库,发现使用“mysql -uroot”命令无法登录。是因为高版本的mysql安装完成之后需要使用临时密码进行登录。
        使用“mysqld_safe --user=mysql --skip-grant-tables --skip-networking &”命令,重新启动mysql服务之后,就可以进行免密登录。
        之后,修改root用户的密码和设置远程访问权限等等操作。但是,root用户的远程访问权限设置之后,数据库远程连接不上,而且“telnet 192.168.0.161 3306”端口也不通,服务器本地telnet 命令3306端口也不同,就像上述“问题描述”中所描述的那样。

3. 解决思路
百度搜索之后,网址:https://blog.youkuaiyun.com/weixin_43671497/article/details/84931578

中有一段话:

        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)
问题机器运行上面运行命令:
1.netstat -talnp 看不到绑定到3306端口的tcp连接
2.ps aux|grep mysql 显示服务在运行
3. lsof -i :3306查看mysql是否运行在3306端口,未有显示mysql服务没有运行在3306端口
        结论:mysql服务虽然在运行,可以通过teminal操作,但没有运行在3306端口,所以通过jdbc连接连接不上。
        后查看网络资料mysql配置中skip-networking未注释,参数skip-networking起的作用是:mysql不再在TCP / IP端口上进行监听,与mysqld的所有互动都必须通过Unix套接字或命名管道进行。
配置文件注释如下:
# Don't listen on a TCP/IP port at all. This can be a security enhancement,# if all processes that need to connect to mysqld run on the same host.# All interaction with mysqld must be made via Unix sockets or named pipes.# Note that using this option without enabling named pipes on Windows# (via the "enable-named-pipe" option) will render mysqld useless!
        将参数skip-networking注释重启mysql服务,jdbc程序连接mysql正常。
        所以,导致无法远程连接mysql的原因是因为参数skip-networking。
        回顾之前的操作,之前mysql安装结束之后,为了解决“mysql -uroot”无法登录的问题,使用 “mysqld_safe --user=mysql --skip-grant-tables --skip-networking &” 命令重启了mysql服务,该命令中有一个参数“–skip-networking”,所以使用命令:SHOW VARIABLES LIKE ‘skip_networking’; 查看,发现参数skip-networking是打开的。

        其实使用“ps aux|grep mysql”命令在查看mysql服务时,也能看到参数skip-networking:

        所以现在所要做的就是将参数skip-networking关闭掉。

4. 解决问题
        仿照之前的操作,现将mysql服务关闭掉,不行就“ps aux|grep mysql”查询到相应的pid之后将对应进行kill掉。然后再使用“mysqld_safe --user=mysql &”命令重新启动服务,之后3306端口就打开了。
        此时,再使用“ps aux|grep mysql”命令在查看mysql服务时,就没有参数skip-networking:


5. 结论
        如果使用 “mysqld_safe --user=mysql --skip-grant-tables --skip-networking &” 命令重启mysql服务,实现了免密登录,完成所需操作之后,一定要记得关闭参数skip-grant-tables 和skip-networking。
 

 

按照上述操作之后远程登陆成功,到此,安装成功。

 

 

 

 

 

 

 

 

 

 

 

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值