Manjaro下安裝mysql數(shù)據(jù)庫及解決ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor...

一、安裝mysql:

第一步:安裝mysql

? ? 安裝命令: sudo pacman -S mysql

第二步:初始化mysql

sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql

如果出現(xiàn)以下信息,則初始化成功:

2018-12-18T13:52:12.107493Z 0 [Warning] [MY-010915] [Server] '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.

2018-12-18T13:52:12.107563Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 1376

2018-12-18T13:52:12.108739Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.

2018-12-18T13:52:12.108748Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead.

2018-12-18T13:52:32.034755Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: uJq1y<0:Y(cx

2018-12-18T13:52:47.269030Z 0 [System] [MY-013170] [Server] /usr/bin/mysqld (mysqld 8.0.13) initializing of server has completed

其中,我加粗的部分為你的mysql root賬號和它的密碼

如果未顯示以上信息,則初始化失敗,建議卸載重裝:

卸載指令:sudo pacman -Rs mysql ,然后刪除/var/lib/mysql目錄:sudo rm -rf? /var/lib/mysql然后重新執(zhí)行第一步。

第三步:設(shè)置開機(jī)自啟

sudo systemctl enable mysqld.service

第四步:啟動MySQL服務(wù)

sudo systemctl start mysqld.service

第五步:連接數(shù)據(jù)庫

mysql -uroot -p

然后輸入你在初始化時得到的mysql的root用戶密碼

想要更改你的mysql賬號密碼:

sudo mysqladmin -u root -p password "新密碼"

本文引用于:https://blog.csdn.net/Bruce_Chou/article/details/85081721

Linux 操作數(shù)據(jù)庫

service mysqld start 啟動MySQL

service mysqld restart 重啟MySQL

service mysqld stop 停止MySQL

mysql -uroot -p 打開本地數(shù)據(jù)庫

show databases; 列出數(shù)據(jù)庫

use database databaseName; 使用數(shù)據(jù)庫databaseName

查看mysql配置信息:status

查看端口號:show global variables like 'port';

show tables; 列出表單

創(chuàng)建表單: 例子: create table tableName(id int auto_increment not null primary key,username varchar(250),passward varchar(205));

drop table tableName; 刪除表單

drop database databaseName; 刪除數(shù)據(jù)庫

插入:

insert into tableName(列名) values(值);

查找:

select * from tableName;

刪除記錄:

delete from tableName where id ='1';

卸載mysql:

先卸載mysql安裝,

sudo pacman -Rs mysql

再:

sudo rm -rf? /var/lib/mysql

sudo rm /etc/my.cnf

python實現(xiàn)增刪改查:

"insert into data_spider (url, data) value(%s, %s)",(item['url'],item['data']))

conn = pymysql.connect(host=database.host,user=database.user,passwd=database.pwd,db=database.dbName)

print("開始")

cursor = conn.cursor()

#設(shè)置數(shù)據(jù)一字典的形式取出:conn.cursor(pymysql.cursors.DictCursor)

sql ="select username,password,user_id from user_infor where username=%s"

try:

#執(zhí)行SQL語句

? ? print("開始查詢")

cursor.execute(sql%(username))

results = cursor.fetchall()

print(results)

print(type(results))

二、解決ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES):

首先,該問題是提示密碼錯誤,可能是你忘記了密碼。此時,可以通過修改配置文件實現(xiàn)免密進(jìn)入mysql:

具體步驟:

進(jìn)入?my.cnf文件

cd /etc/mysql

sudo vim my.cnf

# 在socket=/var/lib/mysql/mysql.sock參數(shù)下加上:

skip-grant-tables

重啟mysql服務(wù):

sudo systemctl stop mysqld.service? ? ?#停止服務(wù)

sudo systemctl start mysqld.service? ? ?#啟動服務(wù)

登錄mysql,輸入密碼時,直接回車即可進(jìn)入

mysql -uroot -p

# 輸入密碼時,直接回車即可

修改密碼:(修改配置的方法相當(dāng)于把你的密碼設(shè)置為了空,所以你直接回車即可登錄,為了確保數(shù)據(jù)庫安全,我們需要修改密碼)

update mysql.user set?authentication_string='newpassword' where user='root' and host='localhost';

修改成功,下次登錄時,輸入新密碼即可。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 夕陽文集 放棄也許是得到 人總是珍惜未得到的,而遺忘了已擁有的。其實抽出點(diǎn)時間來整理一下自己已經(jīng)擁有的東西,你會更...
    開掘者閱讀 253評論 2 1
  • 一天很短 短得來不及擁抱清晨 就已經(jīng)手握黃昏 一年很短 短得來不及細(xì)品初春殷紅竇綠 就要打點(diǎn)素裹秋霜 一生很短 短...
    裴先森閱讀 504評論 0 0

友情鏈接更多精彩內(nèi)容