linux 离线安装mysql

一、软件包下载地址:https://downloads.mysql.com/archives/community/

二、新建目录/tools/soft 目录并重名mysql

mkdir -p /tools/soft
#解压到安装目录
tar -zxvf /tools/soft/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /tools/
#将文件重名称
mv /tools/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz mysql

三、创建mysql用户组和用户并修改权限

groupadd mysql
useradd -r -g mysql mysql

四、创建数据目录并赋予权限

mkdir -p  /data/mysql              #创建目录
chown mysql:mysql -R /data/mysql   #赋予权限

五、配置my.cnf

vim /etc/my.cnf
按下i键贴内容如下
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/tools/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

按:wq保存

六、初始化数据库

#进入安装目录
cd /tools/mysql/bin/
#初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/tools/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
#查看密码
[root@miguvideo-3 soft]# cat /data/mysql/mysql.err 
2020-04-23T08:47:08.671449Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-04-23T08:47:08.763758Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-04-23T08:47:08.835429Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0436c78a-853f-11ea-888d-fa163e1ced08.
2020-04-23T08:47:08.839632Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-04-23T08:47:08.840339Z 1 [Note] A temporary password is generated for root@localhost: L>ysxdro!4BX

#初始密码为L>ysxdro!4BX

七、启动mysql,并更改root 密码

#先将mysql.server放置到/etc/init.d/mysql中
cp /tools/mysql/support-files/mysql.server /etc/init.d/mysql

#ps:很重的一步直接执行service mysql start启动报错 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable解决办法如下 https://www.cnblogs.com/wajika/p/6719805.html   创建链接
ln -s /tools/mysql/bin/mysqld /usr/local/mysql/bin/mysqld

#启动mysql
service mysql start

#查看是否启动 
ps -ef|grep mysql

#添加mysql环境变量
vi /etc/profile
添加如下代码
export MYSQL_HOME=/tools/mysql
export PATH=$PATH:$MYSQL_HOME/bin
#保存
:wq

#更新环境变量
source /etc/profile

#修改用户名密码
[root@miguvideo-3 soft]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

执行下面三部
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;   

#密码修改成功~~   
#修改任何地址都能访问
use mysql                                            #访问mysql库
update user set host = '%' where user = 'root';      #使root能再任何host访问
FLUSH PRIVILEGES;                                    #刷新

                         


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章