溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么初始化MySQL數(shù)據(jù)庫(kù)

發(fā)布時(shí)間:2020-05-29 19:30:10 來(lái)源:億速云 閱讀:1678 作者:鴿子 欄目:系統(tǒng)運(yùn)維

1)初始化隨機(jī)密碼    mysqld --initialize 

[root@host-172-16-61-102 bin]# ./mysqld --initialize

2020-02-15T07:01:38.309015Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-02-15T07:01:38.309069Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

2020-02-15T07:01:38.497402Z 0 [Warning] InnoDB: New log files created, LSN=45790

2020-02-15T07:01:38.541219Z 0 [Warning] InnoDB: Creating foreign key constraint system 

tables.

2020-02-15T07:01:38.553509Z 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: 02fb69c1-4fc1-11ea-8b4e-fa163d34f78d.

2020-02-15T07:01:38.556591Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2020-02-15T07:01:38.980429Z 0 [Warning] CA certificate ca.pem is self signed.

2020-02-15T07:01:39.723869Z 1 [Note] A temporary password is generated for root@localhost: +:NoRLu2kwhd


生成的密碼是:+:NoRLu2kwhd

以上的指令,默認(rèn)讀取配置文件/etc/my.cnf,需要/etc/my.cnf文件中指定了數(shù)據(jù)庫(kù)的地址,并且生成一個(gè)root用戶的密碼,還有如下的參數(shù)可以設(shè)置

--user=mysql  //生成指定用戶的密碼

--datadir=/opt/mysql/mysql/data  //指定生成的數(shù)據(jù)庫(kù)數(shù)據(jù)地址

--defaults-file=/opt/mysql/mysql/etc/my.cnf//指定讀取的配置文件,取代默認(rèn)的配置


2)初始化空密碼    mysqld --initialize-insecure

啟動(dòng)mysqld服務(wù) ./mysqld --user=root

創(chuàng)建密碼

[root@host-172-16-61-102 bin]# mysql -uroot -p

//提示密碼輸入,直接回車(chē)

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MySQL connection id is 11

Server version: 5.7.28 MySQL xxx


Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.


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

//為root創(chuàng)建密碼

MySQL [(none)]> set password = password("root");

Query OK, 0 rows affected, 1 warning (0.00 sec)


MySQL [(none)]> quit


注意:執(zhí)行“mysqld  --initialize”報(bào)錯(cuò)了。提示“initialize specified but the data directory has files in it. Aborting”,大意是提示/opt/mysql/mysql/data數(shù)據(jù)庫(kù)地址下有文件,導(dǎo)致無(wú)法初始化數(shù)據(jù)庫(kù),這個(gè)時(shí)候,可以進(jìn)入到該目錄,將所有的數(shù)據(jù)刪除,說(shuō)明之前已經(jīng)初始化過(guò)

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI