13.4 mysql用戶管理
13.5 經常使用sql語句
13.6 mysql數據庫備份恢復
擴展
SQL語句教程 http://www.runoob.com/sql/sql-tutorial.html
什麼是事務?事務的特性有哪些? http://blog.csdn.net/yenange/article/details/7556094
根據binlog恢復指定時間段的數據 https://blog.csdn.net/lilongsy/article/details/74726002
mysql字符集調整 http://xjsunjie.blog.51cto.com/999372/1355013html
使用xtrabackup備份innodb引擎的數據庫 innobackupex 備份 Xtrabackup 增量備份 http://zhangguangzhi.top/2017/08/23/innobackex%E5%B7%A5%E5%85%B7%E5%A4%87%E4%BB%BDmysql%E6%95%B0%E6%8D%AE/#%E4%B8%89%E3%80%81%E5%BC%80%E5%A7%8B%E6%81%A2%E5%A4%8Dmysql
相關視頻
連接:http://pan.baidu.com/s/1miFpS9M 密碼:86dx
連接:http://pan.baidu.com/s/1o7GXBBW 密碼:ue2fmysql
mysql> grant all on *.* to 'user1'@'127.0.0.1' identified by '123456a'; Query OK, 0 rows affected (0.02 sec)
[root@yong-01 ~]# mysql -uuser1 -p'123456a' Warning: Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'user1'@'localhost' (using password: YES)
[root@yong-01 ~]# mysql -uuser1 -p'123456a' -h127.0.0.1
mysql> grant all on *.* to 'user1'@'localhost' identified by '123456a'; Query OK, 0 rows affected (0.00 sec)
[root@yong-01 ~]# mysql -uuser1 -p123456a
[root@yong-01 ~]# mysql -uuser1 -p123456a mysql> show grants; +-----------------------------------------------------------------------------------------------------------------------+ | Grants for user1@localhost | +-----------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'user1'@'localhost' IDENTIFIED BY PASSWORD '*B012E8731FF1DF44F3D8B26837708985278C3CED' | +-----------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
[root@yong-01 ~]# mysql -uroot -p111111 mysql> show grants for user1@'127.0.0.1'; +-----------------------------------------------------------------------------------------------------------------------+ | Grants for user1@127.0.0.1 | +-----------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'user1'@'127.0.0.1' IDENTIFIED BY PASSWORD '*B012E8731FF1DF44F3D8B26837708985278C3CED' | +-----------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> grant SELECT,UPDATE,INSERT on db1.* to 'user2'@'192.168.180.1' identified by 'passwd'; Query OK, 0 rows affected (0.00 sec)
mysql> show grants for user2@'192.168.180.1'; +------------------------------------------------------------------------------------------------------------------+ | Grants for user2@192.168.180.1 | +------------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'user2'@'192.168.180.1' IDENTIFIED BY PASSWORD '*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0' | | GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user2'@'192.168.180.1' | +------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
mysql> GRANT USAGE ON *.* TO 'user2'@'192.168.180.2' IDENTIFIED BY PASSWORD '*59C70DA2F3E3A5BDF46B68FF5C8B8F25762BCCEF0'; Query OK, 0 rows affected (0.00 sec)
db1
.* TO 'user2'@'192.168.133.1' 把IP改成192.168.133.2,並加上分號 ;mysql> GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user2'@'192.168.180.2'; Query OK, 0 rows affected (0.00 sec)
mysql> show grants for user2@'192.168.180.2'; +------------------------------------------------------------------------------------------------------------------+ | Grants for user2@192.168.180.2 | +------------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'user2'@'192.168.180.2' IDENTIFIED BY PASSWORD '*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0' | | GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user2'@'192.168.180.2' | +------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
mysql> select count(*) from mysql.user; +----------+ | count(*) | +----------+ | 10 | +----------+ 1 row in set (0.00 sec)
mysql> select db from mysql.db; +---------+ | db | +---------+ | test | | test\_% | | db1 | | db1 | +---------+ 4 rows in set (0.01 sec) mysql>
mysql> select db,user from mysql.db; +---------+-------+ | db | user | +---------+-------+ | test | | | test\_% | | | db1 | user2 | | db1 | user2 | +---------+-------+ 4 rows in set (0.00 sec) mysql>
mysql> desc db1.t1; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | id | int(4) | YES | | NULL | | | name | char(40) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | abc | +------+------+ 1 row in set (0.00 sec)
mysql> insert into db1.t1 values (1, 234); Query OK, 1 row affected (0.01 sec) mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | abc | | 1 | 234 | +------+------+ 2 rows in set (0.00 sec)
mysql> update db1.t1 set name='aaa' where id=1; Query OK, 2 rows affected (0.01 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | aaa | | 1 | aaa | +------+------+ 2 rows in set (0.00 sec)
mysql> delete from db1.t1 where id=1; Query OK, 2 rows affected (0.01 sec) mysql> select * from db1.t1; Empty set (0.00 sec)
mysql> truncate table db1.t1; Query OK, 0 rows affected (0.02 sec) mysql> select * from db1.t1; Empty set (0.00 sec) mysql> desc db1.t1; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | id | int(4) | YES | | NULL | | | name | char(40) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
mysql> drop table db1.t1; Query OK, 0 rows affected (0.01 sec) mysql> select * from db1.t1; //由於表的架構已經不存在了 ERROR 1146 (42S02): Table 'db1.t1' doesn't exist mysql>
[root@yong-01 ~]# mysqldump -uroot -p111111 mysql > /tmp/mysqlbak.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 ~]# mysql -uroot -p111111 -e "create database mysql2" Warning: Using a password on the command line interface can be insecure.
[root@yong-01 ~]# mysql -uroot -p111111 mysql < /tmp/mysqlbak.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 ~]# mysql -uroot -p111111 mysql2
mysql> select database(); +------------+ | database() | +------------+ | mysql2 | +------------+ 1 row in set (0.00 sec)
[root@yong-01 ~]# mysqldump -uroot -p111111 mysql user >/tmp/user.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 ~]# mysql -uroot -p111111 mysql2 < /tmp/user.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 ~]# mysqldump -uroot -p111111 -A >/tmp/mysql_all.sql Warning: Using a password on the command line interface can be insecure.
[root@yong-01 ~]# mysqldump -uroot -p111111 -d mysql > /tmp/mysql.sql Warning: Using a password on the command line interface can be insecure.