mysql+phpAdmin

無法登陸

出現(xiàn)字樣:mysqli_real_connect(): (HY000/2002): No such file or directory
打開文件:/Library/WebServer/Documents/phpadmin/libraries/config.default.php
修改為$cfg['Servers'][$i]['host'] = '127.0.0.1';

修改加密規(guī)則

修改加密規(guī)則 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; 

更新密碼(mysql_native_password模式)    
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新的密碼';

禁止訪問

如果出現(xiàn)禁止訪問的字樣,需要配置 apache

Forbidden
You don't have permission to access /phpadmin/ on this server.
打開該文件
/private/etc/apache2/httpd.conf

<Directory />
    AllowOverride none
    Require all denied
</Directory>

改為

<Directory />
    AllowOverride none
    Require all granted
</Directory>

Require all denied ==》 Require all granted

重啟 apache sudo /usr/sbin/apachectl restart

Linux 安裝 mysql

https://www.cnblogs.com/caiyunyun/p/7492373.html
https://blog.csdn.net/github_39533414/article/details/80144890
https://blog.csdn.net/qq_35098526/article/details/80077683

配置 mysql 路徑

執(zhí)行vim ~/.bash_profile

在該文件中添加mysql/bin完整路徑:

PATH=$PATH:/usr/local/mysql/bin

添加完成后,按esc,然后輸入wq保存。

最后在命令行輸入source ~/.bash_profile進(jìn)行加載修改后的配置文件

至此,就可以在全局環(huán)境下通過mysql -u root -p登錄mysql了,會(huì)讓你輸入密碼,

mysql -u root -p12345678

修改密碼:SET PASSWORD FOR'root'@'localhost'=PASSWORD('newpass');

創(chuàng)建用戶
GRANT USAGE ON*.*TO 'test'@'%' IDENTIFIED BY '123456'WITH GRANT OPTION;

重置用戶
ALTER USER 'test'@'%' IDENTIFIED BY '123456';

刷新權(quán)限
flush privileges ;

-- 給用戶test在數(shù)據(jù)庫名為auto_dev上賦EXECUTE(執(zhí)行存儲(chǔ)過程),INSERT,SELECT,UPDATE權(quán)限,@'%'表示從任意ip都可以訪問到這個(gè)數(shù)據(jù)庫
SHOW GRANTS FOR test;
GRANT EXECUTE,INSERT,SELECT,UPDATE ON 數(shù)據(jù)庫名.* TO 'test'@'%';

給所有的權(quán)限:
GRANT ALL PRIVILEGES ON 數(shù)據(jù)庫名.* TO 'test'@'%';

命令行創(chuàng)建數(shù)據(jù)庫

CREATE DATABASE 數(shù)據(jù)庫名; # 創(chuàng)建數(shù)據(jù)庫
show databases; #顯示所有數(shù)據(jù)庫列表
drop database 數(shù)據(jù)庫名;# 刪除數(shù)據(jù)庫
use TestDB;#制定TestDB數(shù)據(jù)庫為當(dāng)前默認(rèn)數(shù)據(jù)庫
create table customers(userid int not null, username varchar(20) not null);#TestDB數(shù)據(jù)庫中創(chuàng)建表customers
show tables;#顯示數(shù)據(jù)庫中的表
drop table customers;#刪除表customers
desc customers;#顯示customers表的結(jié)構(gòu)
insert into customers(userid, username) values(1, 'hujiahui');#向customers表中插入一條記錄
commit;#讓操作及時(shí)生效;
select * from customers;#查詢customers中的記錄
update customers set username='DennisHu' where userid=1;#更新表中的數(shù)據(jù)
delete from customers; #刪除表中的記錄
grant select, insert, update, delete on *.* to hjh@localhost indentified by "123456";#授予hjh用戶訪問數(shù)據(jù)庫的權(quán)限
備注:hjh是Linux用戶名,123456是訪問mysql的密碼

mysql 禁止導(dǎo)出

The MySQL server is running with the --secure-file-priv option so it cannot execute this statement 出現(xiàn)這個(gè)字樣時(shí),需要修改配置。

1.找到 /private/etc/my.cnf
2.增加一行 secure_file_priv=''
3.重啟mysql服務(wù)器

mysql導(dǎo)入導(dǎo)出數(shù)據(jù)庫

1.導(dǎo)出整個(gè)數(shù)據(jù)庫(mac下數(shù)據(jù)庫導(dǎo)出套tmp文件夾,否則可能會(huì)報(bào)錯(cuò))
mysqldump -u 用戶名 -p 數(shù)據(jù)庫名 > 導(dǎo)出的文件名
mysqldump -u dbuser -p dbname > tmp/dbname.sql
2.導(dǎo)出一個(gè)表
mysqldump -u 用戶名 -p 數(shù)據(jù)庫名 表名> 導(dǎo)出的文件名
mysqldump -u dbuser -p dbname users> dbname_users.sql

3.導(dǎo)出一個(gè)數(shù)據(jù)庫結(jié)構(gòu)
mysqldump -u dbuser -p -d --add-drop-table dbname >d:/dbname_db.sql
-d 沒有數(shù)據(jù) --add-drop-table 在每個(gè)create語句之前增加一個(gè)drop table

4.導(dǎo)入數(shù)據(jù)庫
常用source 命令
進(jìn)入mysql數(shù)據(jù)庫控制臺(tái),如
mysql -u root -p
mysql>use 數(shù)據(jù)庫
然后使用source命令,后面參數(shù)為腳本文件(如這里用到的.sql)
mysql>source d:/dbname.sql
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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