標籤:
1. 忘記root密碼
http://www.lishiming.net/thread-252-1-1.html
進入mysql
which mysql
/usr/local/mysql/bin/mysql 沒有設定密碼之前可以這樣子開啟mysql
登入/usr/local/mysql/bin/mysql -uroot -p123456
如果忘記root密碼或其他使用者密碼,不要急,按下面操作即可。
1. 編輯mysql主設定檔 my.cnf
vim /etc/my.cnf
在[mysqld]欄位下添加參數
skip-grant 不需要授權
2. 重啟資料庫服務
service mysqld restart
3. 這樣就可以進入資料庫不用授權了
mysql -uroot
4. 修改相應使用者密碼
use mysql;
update user set password=password(‘aminglinux‘) where user=‘root‘;
flush privileges;
5. 修改/etc/my.cnf 去掉 skip-grant , 重啟mysql服務
重啟
/etc/init.d/mysqld restart
登入/usr/local/mysql/bin/mysql -uroot -paminglinux
看user表
use mysql;
select * from user\G;
=============
2.
skip-name-resolve(禁止解析網域名稱)
skip-innodb (是mysql的引擎)
vim /etc/my.cnf 在配置裡面加上上面兩個,然後在/data/mysql 有幾個檔案會消失
3. 配置慢查詢日誌
#log_slow_queries = /path/to/slow_queries
#long_query_time = 1
查看設定檔,預設在下面檔案找
vim /etc/init.d/mysqld 進去尋找conf=/etc/my.cnf
4. innodb與myisam 常用mysql引擎,總結一下
http://www.lishiming.net/thread-97-1-1.html
5. mysql配置調優
http://www.lishiming.net/thread-5758-1-1.html
6. mysql常用操作
mysql -uroot -paminglinux
或者 mysql -uroot -h127.0.0.1 -paminglinux
mysql -uroot -h192.168.11.190 -P3306 -paminglinux
mysql -uroot -S /tmp/mysql.sock -paminglinux 可以用sock去通訊,只可以在本地用
查看都有哪些庫 show databases;
調用系統的命令 system ls
查看某個庫的表 use db; show tables;
查看錶的欄位結構 desc tb;
查看建表語句 show create table tb\G; \G顯示比較有規則一點
當前是哪個使用者 select user();
當前庫 select database();
建立庫 create database db1; mysql -uroot -paminglinux -e "create database discuz2"
建立表 create table t1 (`id` int(4), `name` char(40));
insert into t1 values(1, ‘aming‘);
insert into t1 (`id`) values(2); 插入單個欄位
select * from t1;
查看資料庫版本 select version();
查看mysql狀態 show status;
修改mysql參數 show variables like ‘max_connect%‘; set global max_connect_errors = 1000;
查看mysql隊列 show processlist; ===============
grant all on *.* to ‘root‘@‘10.0.2.100‘ identified by ‘123456‘; *.*代表所有的庫和表都授權
建立普通使用者並授權 grant all on *.* to user1 identified by ‘123456‘;
grant all on db1.* to ‘user2‘@‘10.0.2.100‘ identified by ‘111222‘;
flush privileges; 重新整理一下磁碟
grant all on db1.* to ‘user3‘@‘%‘ identified by ‘231222‘;
更改密碼 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;
刪除表欄位 delete from t1 where id=3;
清空表的資料 truncate table db1.t1;
刪除表 drop table db1.t1;
刪除資料庫 drop database db1;
修複表 repair table tb1 [use frm];
show processlist ; 看看任務都有哪些 show full processlist ;
show variables like ‘%timeout%‘;
在設定檔裡面加上,兩個必須同時用從可以
interactive_timeout = 10
wait_timeout=10
如果更改mysql的設定檔my.conf 就需要重啟mysql,現在不需要重啟就可以生效的方法(不是全域,全域需要寫入到設定檔裡面)
set global interactive_timeout = 10;
把重啟的服務放到系統的環境 /etc/rc.local 下面,就可以開機自動生效=========
/usr/local/apache2/bin/apachectl start
查看文章內容的表
select * from pre_forum_post\G;
搜尋文章
select * from pre_forum_post where subject like ‘%sjs%‘;
7. mysql備份與恢複
備份資料庫 mysqldump -uroot -paminglinux db >1.sql
恢複 mysql -uroot -paminglinux db <1.sql
mysql -uroot -paminglinux -e "create database discuz2"
備份時指定字元集 mysqldump -uroot -paminglinux --default-character-set=utf8 db >1.sql
只備份表結構 mysqldump -uroot -paminglinux --default-character-set=utf8 -d db >1.sql
恢複指定字元集 mysql -uroot -paminglinux --default-character-set=utf8 db < 1.sql
只備份一個表 mysqldump -uroot -paminglinux db tb1 > 2.sql
8. 一台mysql伺服器啟動多個連接埠
http://www.lishiming.net/thread-63-1-1.html
http://www.aminglinux.com/bbs/forum.php?mod=viewthread&tid=6509&highlight=phpmyadmin
安裝mysqlamin 管理平台
第四部分 mysql相關