LAMP第四部分mysql操作

來源:互聯網
上載者:User

標籤:

1. 忘記root密碼
編輯mysql主設定檔 my.cnf 在[mysqld]欄位下添加參數  skip-grant  ,重啟資料庫服務,這樣就可以進入資料庫不用授權了 mysql -uroot ,修改相應使用者密碼 use mysql; update user set password=password(‘your password‘) where user=‘root‘;flush privileges;  最後修改/etc/my.cnf 去掉 skip-grant , 重啟mysql服務

2. skip-innodb   我們可以增加這個參數不使用innodb引擎。

3. 配置慢查詢日誌
#log_slow_queries = /path/to/slow_queries
#long_query_time = 1

4. mysql常用操作
查看都有哪些庫  show databases;
查看某個庫的表 use db; show tables; 
查看錶的欄位 desc tb;
查看建表語句 show create table tb;
當前是哪個使用者  select user();
當前庫 select database();
建立庫 create database db1; 
建立表 create table t1 (`id` int(4), `name` char(40));  
查看資料庫版本 select version(); 
查看mysql狀態 show status;
修改mysql參數 show variables like ‘max_connect%‘; set global max_connect_errors = 1000; 
查看mysql隊列 show processlist; 
建立普通使用者並授權 grant all on *.* to user1 identified by ‘123456‘; 
grant all on db1.* to ‘user2‘@‘10.0.2.100‘ identified by ‘111222‘; 
grant all on db1.* to ‘user3‘@‘%‘ identified by ‘231222‘;insert into tb1 (id,name) values(1,‘aming‘);
更改密碼 UPDATE mysql.user SET password=PASSWORD("newpwd") WHERE user=‘username‘ ;   
查詢 select count(*) from mysql.user; select * from mysql.db; select * from mysql.db where host like ‘10.0.%‘; 
插入 update db1.t1 set name=‘aaa‘ where id=1;  
清空表 truncate table db1.t1; 
刪除表 drop table db1.t1; 
刪除資料庫 drop database db1; 
修複表 repair table tb1 [use frm];

5. mysql備份與恢複
備份 mysqldump -uroot -p db >1.sql 
恢複 mysql -uroot -p db <1.sql  
只備份一個表  mysqldump -uroot -p db tb1 > 2.sql
備份時指定字元集 mysqldump -uroot -p --default-character-set=utf8  db >1.sql
恢複也指定字元集 mysql -uroot -p --default-character-set=utf8  db  < 1.sql

擴充知識:
myisam 和innodb引擎對比  http://www.pureweber.com/article/myisam-vs-innodb/
一台mysql伺服器啟動多個連接埠 http://www.lishiming.net/thread-63-1-1.html
SQL語句教程  http://blog.51cto.com/zt/206 
sql教程pdf文檔   http://class.ccshu.net/00864091/ ... %95%99%E7%A8%8B.pdf
什麼是事務?事務的特性有哪些?  http://blog.csdn.net/yenange/article/details/7556094
mysql常用引擎  http://c.biancheng.net/cpp/html/1465.html
批量更改表的引擎    http://www.361way.com/change-mysql-engine/1729.html
mysql 二進位日誌binlog的模式   http://lihuipeng.blog.51cto.com/3064864/833017
mysql根據binlog恢複指定時間段的資料   http://www.centoscn.com/mysql/2015/0204/4630.html
mysql字元集調整  http://xjsunjie.blog.51cto.com/999372/1355013
使用xtrabackup備份innodb引擎的資料庫  http://www.aminglinux.com/bbs/thread-956-1-1.html
innobackupex 備份 Xtrabackup 增量備份 http://www.aminglinux.com/bbs/thread-1012-1-1.html

LAMP第四部分mysql操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.