MySql教程

linux离线安装mysql

本文主要是介绍linux离线安装mysql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.判断系统是多少位的

file /sbin/init

2.下载linux安装包

  

  5.7.25.64位安装包

    链接:https://pan.baidu.com/s/13vFuRikwJaI96K0AmUQXzg
    提取码:ga7h


  其他版本安装 去官网下载:https://dev.mysql.com/downloads/mysql/

3.创建mysql文件夹  

mkdir /mysql

4.检查mysql文件是否存在

root@localhost mysql]# rpm -qa |grep mysql
mysql-libs-5.1.71-1.el6.i686
[root@localhost mysql]# rpm -e mysql-libs-5.1.71-1.el6.i686 --nodeps

5.解压安装包

tar -xvf mysql-5.7.25-1.el6.x86_64.rpm-bundle.tar 

6.进行安装

复制代码
1.rpm -ivh mysql-community-common-5.7.25-1.el6.x86_64.rpm --nodeps

warning: mysql-community-common-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-common ########################################### [100%]

2.rpm -ivh mysql-community-test-5.7.25-1.el6.x86_64.rpm --nodeps

warning: mysql-community-test-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-test   ########################################### [100%]

3.rpm -ivh mysql-community-libs-5.7.25-1.el6.x86_64.rpm --nodeps

warning: mysql-community-libs-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-libs   ########################################### [100%]

4.rpm -ivh mysql-community-client-5.7.25-1.el6.x86_64.rpm --nodeps

warning: mysql-community-client-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-client ########################################### [100%]

5.rpm -ivh mysql-community-server-5.7.25-1.el6.x86_64.rpm --nodeps

warning: mysql-community-server-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-server ########################################### [100%]

6.rpm -ivh mysql-community-devel-5.7.25-1.el6.x86_64.rpm --nodeps

warning: mysql-community-devel-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:mysql-community-devel  ########################################### [100%]

7.rpm -ivh mysql-community-test-5.7.25-1.el6.x86_64.rpm --nodeps

warning: mysql-community-test-5.7.25-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
    package mysql-community-test-5.7.25-1.el6.x86_64 is already installed
 
  
MySQL8.0 安装报错问题
 
1.安装server:
  rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm
 
warning: mysql-community-server-8.0.15-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 
Preparing... ################################# [100%]
file /etc/my.cnf from install of mysql-community-server-8.0.15-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64

2.出现以上问题在命令后面加上 --force --nodeps
  rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm --force --nodeps

warning: mysql-community-server-8.0.15-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%] 
Updating / installing... 
1:mysql-community-server-8.0.15-1.e################################# [100%]
复制代码

7.检查并启动mysql服务

复制代码
1. service mysqld status
    
    输出mysqld is stopped

2. service mysqld start

    输出Initializing MySQL database:                               [  OK  ]
    输出Starting mysqld:                                           [  OK  ]

3. service mysqld status
    
    输出mysqld (pid  3781) is running...    
复制代码

8. 登录mysql并修改密码

复制代码
1.获取临时密码:
    more /var/log/mysqld.log | grep "A temporary password"

2.登录:
    mysql -hlocalhost -p

3.修改密码策略:
    设置密码长度: set global validate_password_policy=0;
    设置长度最低为:set global validate_password_length=4;
    设置保存:flush privileges;

4.修改密码:
    set password=password('123456');
    设置保存:flush privileges;
    
5.使用设置的密码登录:
    mysql -hlocalhost -p123456
复制代码

9.设置mysql日志模式(开启日志模式后可以根据日志回滚数据)

复制代码
1.检查日志是否开启,默认为off关闭
  show variables like 'log_bin';

2.编辑/etc/my.cnf
  添加:
     log_bin=binary-log
     server_id=1

3.重启mysql服务
    service mysqld restart

4.检查日志是否开启
  show variables like 'log_bin';
复制代码

 

安装mysql-8.0.22-linux-glibc2.12-i686.tar.xz

 

1.将mysql-8.0.22-liunx-glibc2.12-i686.tar.xz包放入 usr/local 文件夹,解压,重命名为mysql

解压: tar -xvf mysql-8.0.22-liunx-glibc2.12-i686.tar.xz

重命名: mv mysql-8.0.22-liunx-glibc2.12-i686.tar.xz mysql

2.进入usr/local目录下创建用户并授权

复制代码
进入目录: cd /usr/local

创建用户组: groupadd mysql

创建用户:useradd -r -g mysql mysql

授权: chown -R mysql:mysql ./
复制代码

3.进入mysql目录下,创建data文件夹,初始化数据

复制代码
创建文件夹: mkdir data

初始化数据库: bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
复制代码

4.修改mysql和mysql/data目录的用户

修改mysql文件夹权限: chown -R root:root ./

修改data文件夹权限: chown -R mysql:mysql data

5.在support-files文件夹下创建my-default.cnf文件,配置权限,复制文件

复制代码
进入文件夹: cd support-files/

创建文件: touch my-default.cnf

文件授权: chmod 777 ./my-default.cnf

复制文件并重命名: cp support-files/my-default.cnf /etc/my.cnf
复制代码

6.配置my.cnf

复制代码
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp
port = 5186
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
log_bin_trust_function_creators = ON
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
复制代码

7.设置开机自启

进入 support-files目录: cd support-files

复制文件: cp mysql.server /etc/init.d/mysql

设置: chmod +x /etc/init.d/mysql

8.注册服务

复制代码
注册服务: chkconfig --add mysql

没有注册服务命令:
    
    1. rpm -aq |grep chkconfig

    2. export PATH=/sbin:$PATH

    3. chkconfig

    4. echo $PATH

    5. PATH="$PATH":/sbin

    6. echo $PATH
复制代码

9.查看是否成功

1. chkconfig --add mysql

2. chkconfig --list mysql

10.配置Id.so.conf,配置环境变量

复制代码
编辑Id.so.conf : vim /etc/ld.so.conf

添加: /usr/local/mysql/lib

:wq保存推出

配置环境变量:vim /etc/profile
    
        新增内容:#MYSQL ENVIRONMENT
          export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib

:wq保存推出

执行: source /etc/profile
复制代码

11.登录mysql数据库

复制代码
启动服务: service mysql start

登录mysql数据库: mysql -uroot -p

修改mysql密码: alter user 'root'@'localhost' identified by '123456';

退出:exit
复制代码

12.开启Navicat远程连接

复制代码
登录: mysql -uroot -p

进入数据库: use mysql

查看用户信息: select host, user, authentication_string, plugin from user;

授权用户可以远程登录: GRANT ALL ON *.* TO 'root'@'%';

立即生效: flush privileges;

修改用户密码: ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

立即生效: FLUSH PRIVILEGES;

退出: exit

重启mysql服务: service mysql restart
复制代码

授权报:ERROR 1410 (42000): You are not allowed to create a user with GRANT 错误

修改host: update user set host='%' where user='root';(执行2次)

再执行:GRANT ALL ON *.* TO 'root'@'%';

 安装后navicat因为防火墙,连接不上mysql数据库报,报错10060:

复制代码
centos7的防火墙相关:
    
    防火墙状态: firewall-cmd --state
    
    关闭防火墙:systemctl stop firewalld.service

    禁止开机自动启动:systemctl disable firewalld.service

centos7以下的防火墙相关:

    关闭防火墙: service iptables stop
    
    禁止开机自动启动: chkconfig iptables off
复制代码
这篇关于linux离线安装mysql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!