python 操做mysql 的網站:https://www.cnblogs.com/pycode/p/mysql-orm.htmlhtml
1 修改MySQL的登陸設置:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存而且退出vi。
2.從新啓動mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
3.登陸並修改MySQL的root密碼
# /usr/bin/mysql python
mysql> use mysql; mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; sql
mysql> FLUSH PRIVILEGES; 數據庫
mysql> quit socket
/etc/init.d/mysql restart
mysql -u root -p
Enter password: <輸入新設的密碼newpassword>
mysql> ide
4 建立用戶網站
create user 'kobe'@'localhost' identified by 'admin@123'; 將localhost 改成%s 表示外網可以訪問。ui
5 建立數據庫rest
create databases kobesystem
6 對用戶設置權限
GRANT ALL PRIVILEGES ON *.* TO 'kobe'@'%' IDENTIFIED BY 'Admin@123' WITH GRANT OPTION;
7 將數據庫和用戶綁定
grant all privileges on haildb.* to hail@localhost identified by 'hail';haildb 爲數據庫,hail 爲用戶hail 爲密碼