- 開(kāi)啟遠(yuǎn)程登錄(或局域網(wǎng)訪問(wèn))
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
flush privileges;
select host,user from user;
- Access denied for user ''@'localhost' to database 'mysql'
1. 關(guān)閉mysql
service mysqld stop
2. 屏蔽權(quán)限
mysqld_safe --skip-grant-table
屏幕出現(xiàn): Starting demo from .....
3. 新開(kāi)起一個(gè)終端輸入
mysql -u root mysql
mysql> delete from user where USER='';
mysql> FLUSH PRIVILEGES;//記得要這句話涵但,否則如果關(guān)閉先前的終端飞蹂,又會(huì)出現(xiàn)原來(lái)的錯(cuò)誤
mysql> \q
- centos7安裝mysql
- 下載、安裝倉(cāng)庫(kù)
在命令行中輸入
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- 安裝本地包
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 安裝mysql
yum -y install mysql-community-server
- 啟動(dòng)mysql般妙,然后查看啟動(dòng)狀態(tài)
systemctl start mysqld.service
systemctl status mysqld.service
- 查看root的隨機(jī)密碼
grep "password" /var/log/mysqld.log
- 使用隨機(jī)密碼登錄mysql
mysql -uroot -p
# 輸入上步找到的密碼
- 修改默認(rèn)密碼
# 先修改密碼規(guī)則懦鼠,可以使用簡(jiǎn)單密碼
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
- 刪除本地倉(cāng)庫(kù)钻哩,已免經(jīng)常更新
yum -y remove mysql57-community-release-el7-10.noarch
- mysql編碼utf8
- 查看當(dāng)前編碼
show variables like 'character%'
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
- 修改配置中編碼
# 退出mysql
exit
# 然后編輯配置文件
[root@VM_0_14_centos ~]# vim /etc/my.cnf
# 在[mysqld] 下面添加下行數(shù)據(jù)
character_set_server=utf8
# 保存退出
:wq
- 重啟mysql
systemctl restart mysqld
- mysql導(dǎo)入導(dǎo)出
- mysql數(shù)據(jù)庫(kù)導(dǎo)出
輸入以下命令之后再輸入密碼即可導(dǎo)出到指定位置
[root@VM_0_14_centos ~]# mysqldump -uroot -p nhh_vendor_management_test > /root/vm.sql
- mysql數(shù)據(jù)庫(kù)導(dǎo)入
登錄數(shù)據(jù)并新建數(shù)據(jù)庫(kù)
create datatable dbname;
導(dǎo)入數(shù)據(jù)庫(kù)
[root@VM_0_14_centos ~]# mysql -uroot -p vm < /root/vm.sql