centos7安裝 mysql5 7,自定義目錄

2021-10-01 20:20:21 字數 3836 閱讀 8750

shell> yum search libaio

shell> yum install libaio

shell>

mkdir /prod/db

shell>

cd /prod/db

shell>

wget

shell>

tar -axvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

shell>

mv /prod/db/mysql-5.7.27-linux-glibc2.12-x86_64 mysql

shell>

cd mysql

shell>

groupadd mysql

shell>

useradd -r -g mysql -s /bin/false mysql

shell>

ln -s /prod/db/mysql mysql

shell> mysql/bin/mysqld --user=mysql --basedir=/prod/db/mysql --datadir=/prod/db/mysql/data/ --initialize

grant

allprivilegeson*

.*to'root'@'%

' identified by 'yourpassword' with

grant

option

;flush privileges

;exit

[client]

port = 3306

socket = /prod/db/mysql/mysql.sock

[mysqld]

port = 3306

basedir=/prod/db/mysql

datadir=/prod/db/mysql/data

socket=/prod/db/mysql/mysql.sock

pid-file=/prod/db/mysql/mysql.pid

explicit_defaults_for_timestamp

log_error=/prod/db/mysql/log/mysql-error.log

slow_query_log_file =/prod/db/mysql/log/mysql-slow.log

shll> yum search libaio

shll> yum install libaio

shell>

groupadd mysql

shell>

useradd -r -g mysql -s /bin/false mysql

-s /bin/false 是禁止使用者登入centos系統

shell>

wget

shell>

tar -axvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

shell>

mv /prod/db/mysql-5.7.27-linux-glibc2.12-x86_64 mysql

shell>

ln -s /prod/db/mysql mysql

mysql/bin/mysqld --user=mysql --basedir=/prod/db/mysql --datadir=/prod/db/mysql/data/  --initialize
mysql軟連線指向/prod/db/mysql

sql

>

set password=password(

'yourpassword'

);

sql

>

grant

allprivilegeson*

.*to'root'@'%

' identified by 'yourpassword' with

grant

option

;

sql

> flush privileges

;

問題一

shell> mysqld --initialize的時候出現了--initialize specified but the data directory has files in it. aborting. 錯誤
解決方法:

a、檢查my.cnf檔案中datadir配置路徑下,是否有data資料夾

b、檢查data資料夾下是否為空,不為空則清空資料夾

問題二:

使用mysql -uroot -p密碼,連線資料庫,出現

shell> error 2002 (hy000): can't connect to local mysql server through socket '/prod/db/mysql/run/mysql.sock' (2)
解決方法:

shell>

service mysql restart

問題三

安裝完成後無法獲取初始密碼。

解決方法:

1. 在配置檔案/prod/db/mysql/my.cnf中 [mysqld] 這一項下新增skip-grant-tables 這個配置,然後儲存。

2. 密登入:輸入 mysql -u root -p 命令然後回車,當需要輸入密碼時,直接按enter鍵。

3. 重置密碼:

配置 my.cnf檔案

shell>

vi mysql/my.cnf

[mysqld]

skip-grant-tables

密登入

shell> mysql -u root -p
sql

>

use mysql;

sql>

update

user

set authentication_string=password(

'新密碼'

)where

sql>

user

='root'

and host=

'%';

sql> flush privileges

;

說明:執行sql語句的時候,如果出現error 1290 (hy000): the mysql server is running with the --skip-grant-tables option so it cannot execute this statement. 則需要先執行一下flush privileges.刪除掉my.cnf中的免密設定,重啟mysql即可。

Centos7離線安裝mysql5

2.將部署包存放到 opt 資料夾下 3.解壓並安裝 cd opt mkdir mysql tar xvf opt mysql 5.7.30 1.el7.x86 64.rpm bundle.tar c opt mysql cd opt mysql rpm uvh rpm nodeps force1....

Centos7使用yum安裝Mysql5 7

centos7的yum源中預設是沒有mysql,因為現在已經用mariadb代替mysql了。安裝mysql rpm包 rpm ivh mysql57 community release el7 11.noarch.rpm 安裝mysql yum install mysql community se...

Centos 7 使用yum安裝mysql 5 7

wget 2 安裝mysql yum y install mysql57 community release el7 10.noarch.rpm yum y install mysql community server 3 啟動mysql systemctl start mysqld.service...