日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Linux 下mysql5.7安装搬运 该安装说明坑最少

發(fā)布時間:2024/7/5 数据库 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux 下mysql5.7安装搬运 该安装说明坑最少 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文搬運來自CSDN?請叫我猿叔叔?的博客https://blog.csdn.net/qq_35206261/article/details/81321201?

遵循?CC 4.0 by-sa?版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接和本聲明。

?

一. 簡介
? ? ? ? ? 下載路徑:https://dev.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

? ? ? ? ? ?系統(tǒng)環(huán)境: centOS 7,? mysql 5.7.18

二. 安裝步驟
2.1 卸載舊的mysql
2.1.1 刪除mysql的安裝文件
? ? ? ? ?查詢mysql的安裝文件:??

[root@ali228 ~]# find / -name mysql /usr/local/env/mysql /usr/local/env/mysql/mysql /usr/local/env/mysql/mysql/bin/mysql /usr/local/env/mysql/mysql/include/mysql /usr/local/env/mysql/mysql/data/mysql [root@ali228 ~]#

?


? ? ? ? ?卸載:

[root@ali228 ~]# rm -rf /usr/local/env/mysql/mysql [root@ali228 ~]#

?


2.1.2 刪除mysql的配置文件
? ? ? ? ?刪除/etc/my.cnf文件

[root@ali228 ~]# rm -rf /etc/my.cnf

?


? ? ? ? ?刪除/etc/init.d/下跟mysql有關(guān)的全部文件,一般包括mysql文件或mysqld文件。

[root@ali228 mysql]# rm -rf /etc/init.d/mysql [root@ali228 mysql]# rm -rf /etc/init.d/mysqlId

?


2.1.3 刪除mysql用戶和用戶組

[root@ali228 ~]# userdel mysql userdel: user 'mysql' does not exist

至此,卸載OK!

?

2.2 安裝MySQL
2.2.1 下載安裝包mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
? ? ? ? ?安裝包路徑:?https://dev.mysql.com/downloads/mysql/5.7.html#downloads

? ? ? ? ?上傳mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz到/usr/local/env/mysql目錄下并解壓

[root@ali228 ~]# cd /usr/local/env/mysql/ [root@ali228 mysql]# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

? ? ? ? ? ?重命名為mysql

?

2.2.2 添加用戶組mysql和用戶mysql,并將其添加到mysql用戶組中

[root@ali228 mysql]# groupadd mysql [root@ali228 mysql]# useradd -r -g mysql mysql


?注:? useradd -r參數(shù)表示mysql用戶是系統(tǒng)用戶,不可用于登錄系統(tǒng)。

?? ? ? ? ? useradd -g參數(shù)表示把mysql用戶添加到mysql用戶組中。

2.2.3?檢查是否安裝了 libaio

[root@baidu64 ~]# rpm -qa | grep libaio

?


如果沒有安裝,使用如下命令安裝

[root@baidu64 ~]# yum search libaio

?


?2.2.4 配置my.cnf文件

[root@baidu64 ~]# touch /etc/my.cnf

?


注意: 使用默認(rèn)的644權(quán)限和用戶,不要做修改;

將如下內(nèi)容拷貝到里面:

[mysql] # 設(shè)置mysql客戶端默認(rèn)字符集 default-character-set=utf8 socket=/tmp/mysql.sock[mysqld] #skip-name-resolve #設(shè)置3306端口 port=3306 socket=/tmp/mysql.sock# 設(shè)置mysql的安裝目錄 basedir=/usr/local/env/mysql/mysql # 設(shè)置mysql數(shù)據(jù)庫的數(shù)據(jù)的存放目錄 datadir=/usr/local/env/mysql/mysql/data # 允許最大連接數(shù) max_connections=200 # 服務(wù)端使用的字符集默認(rèn)為8比特編碼的latin1字符雿 character-set-server=utf8 # 創(chuàng)建新表時將使用的默認(rèn)存儲引擿 default-storage-engine=INNODB #lower_case_table_name=1 max_allowed_packet=16M

?



2.2.5?創(chuàng)建data文件夾

[root@baidu64 mysql]# pwd /usr/local/env/mysql/mysql [root@baidu64 mysql]# mkdir data

?


2.2.6?將mysql目錄的所屬用戶和組改為mysql

[root@baidu64 mysql]# chown -R mysql:mysql ./

?


2.2.7?初始化mysqld 生成初始化密碼

[root@baidu64 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/env/mysql/mysql --datadir=/usr/local/env/mysql/mysql/data

?


此時,控制臺打印如下:

2018-10-24T04:25:13.673365Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-10-24T04:25:15.808961Z 0 [Warning] InnoDB: New log files created, LSN=45790 2018-10-24T04:25:16.105505Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-10-24T04:25:16.184776Z 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: cec94f21-d744-11e8-a0b5-fa163ed8e403. 2018-10-24T04:25:16.188372Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2018-10-24T04:25:16.189074Z 1 [Note] A temporary password is generated for root@localhost: i;lknXwO;5,s [root@baidu64 mysql]#

?


結(jié)尾:?i;lknXwO;5,s 就是初始化的密碼。

3 常規(guī)配置
3.1 設(shè)置開機啟動
3.1.1 復(fù)制mysql.server腳本到資源目錄,并賦予執(zhí)行權(quán)限:

[root@baidu64 mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld [root@baidu64 mysql]# chmod +x /etc/rc.d/init.d/mysqld

?


3.1.2 將 mysqld 服務(wù)加入到系統(tǒng)服務(wù)并檢測是否生效:?

[root@baidu64 mysql]# chkconfig --add mysqld [root@baidu64 mysql]# chkconfig --list mysqld Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'.mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off



得到如下結(jié)果說明生效。

注:?查看啟動項:chkconfig --list | grep -i mysql? ? ? ? 刪除啟動項:chkconfig --del mysql

啟動mysqld:

[root@baidu64 mysql]# service mysqld start Starting MySQL.Logging to '/usr/local/env/mysql/mysql/data/baidu64.err'. [ OK ]

3.2?配置環(huán)境變量
3.2.1 打開/etc/profile配置文件,添加如下內(nèi)容:
#mysql環(huán)境變量
PATH=$PATH:/usr/local/env/mysql/mysql/bin
export PATH
3.2.2 執(zhí)行命令,使其生效:
[root@baidu64 mysql]# source /etc/profile
3.2.3 校驗是否成功:

[root@baidu64 mysql]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/env/jdk/jdk8/jdk1.8.0_171/bin:/root/bin:/home/env/jdk/jdk8/jdk1.8.0_171/bin:/usr/local/env/mysql/mysql/bin

?

3.3? 初次登錄 修改訪問密碼
3.3.1 無密碼登錄

[root@baidu64 mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.18Copyright (c) 2000, 2017, 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>

?


注意: 此時密碼使用上面自動生成的初始化密碼:??i;lknXwO;5,s 即可

3.3.2 修改登錄密碼:

mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> update user set authentication_string=PASSWORD('123456') where User='root'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 1mysql>

?


3.4 允許遠(yuǎn)程訪問

mysql> grant all privileges on *.* to root@"%" identified by "password" with grant option; Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)mysql>

?


3.5 使用navicate遠(yuǎn)程連接報錯
如果使用navicate進(jìn)行遠(yuǎn)程連接訪問,報如下錯誤:

?

?

解決方法如下:

3.5.1 關(guān)閉mysql服務(wù)

[root@baidu64 mysql]# service mysql stop Redirecting to /bin/systemctl stop mysql.service

?


3.5.2 修改/etc/my.cnf修改為無密碼登錄
在my.cnf配置文件添加如下內(nèi)容:

# mysql無密碼登錄 skip-grant-tables

?


3.5.3 重啟mysql服務(wù)

[root@baidu64 mysql]# service mysql restart Redirecting to /bin/systemctl restart mysql.service

?


3.5.4 無密碼登錄mysql
注意: 此時登錄不帶p參數(shù):

[root@baidu64 mysql]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.18 MySQL Community Server (GPL)Copyright (c) 2000, 2017, 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>

?


3.5.5 再次修改mysql密碼:

mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> update mysql.user set authentication_string=password('123456') where user='root' ; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 2 Changed: 1 Warnings: 1mysql>

?


3.5.6 然后將my.cnf無密碼登錄配置去掉(就是上面剛加的那句話)
3.5.7 退出mysql,并重啟:

mysql> quit Bye [root@baidu64 mysql]# service mysql restart Redirecting to /bin/systemctl restart mysql.service [root@baidu64 mysql]#

?


3.5.8 再次使用navicat連接:

?


如此? OK!

?

轉(zhuǎn)載于:https://www.cnblogs.com/blackdeng/p/11424104.html

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的Linux 下mysql5.7安装搬运 该安装说明坑最少的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。