操作環(huán)境:cenos7.0
1、mysql的安裝
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm? ? ? #cenos7把mysql從默認(rèn)列表中刪除了,需要自行下載
rpm -ivh mysql-community-release-el7-5.noarch.rpm? ? #將文件下載到本地,然后安裝
yum -y install mysql mysql-server mysql-devel
++++++
Installed:
? mysql-community-client.x86_64 0:5.6.42-2.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? mysql-community-devel.x86_64 0:5.6.42-2.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? mysql-community-libs.x86_64 0:5.6.42-2.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? mysql-community-server.x86_64 0:5.6.42-2.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Dependency Installed:
? mysql-community-common.x86_64 0:5.6.42-2.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? perl-DBI.x86_64 0:1.627-4.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? perl-Data-Dumper.x86_64 0:2.145-3.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? perl-IO-Compress.noarch 0:2.061-2.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? perl-Net-Daemon.noarch 0:0.48-5.el7? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? perl-PlRPC.noarch 0:0.2020-14.el7? ? ? ? ? ? ?
++++++
2、打開服務(wù)器端
service mysqld start
3、進(jìn)入客戶端
mysql -u root -p? #默認(rèn)無密碼
4、查看、使用數(shù)據(jù)庫,查看表
show databases;
use mysql;
show tables;
5、常用命令實(shí)例
1 mysql數(shù)據(jù)庫使用總結(jié)
2 本文主要記錄一些mysql日常使用的命令,供以后查詢。
3 1.更改root密碼
4 mysqladmin -uroot password 'yourpassword'
5 2.遠(yuǎn)程登陸mysql服務(wù)器
6 mysql -uroot -p -h192.168.137.10 -P3306
7 3.查詢數(shù)據(jù)庫
8 show databases;
9 4.進(jìn)入某個(gè)數(shù)據(jù)庫
10 use databasename;
11 5.列出數(shù)據(jù)庫中的表
12 show tables;
13 6.查看某個(gè)表全部字段
14 desc slow_log;
15 show create table slow_log\G; (不僅可以顯示表信息,還可以顯示建表語句)
16 7.查看當(dāng)前用戶
17 select user();
18 8.查看當(dāng)前所在數(shù)據(jù)庫
19 select database();
20 9.創(chuàng)建新數(shù)據(jù)庫(可以指定字符集)
21 create database db1 charset utf8;
22 10.創(chuàng)建新表
23 create table t1 (`id` int(4), `name` char(40));
24 11.查看數(shù)據(jù)庫版本
25 select version();
26 12.查看數(shù)據(jù)庫狀態(tài)
27 show status; 當(dāng)前會(huì)話狀態(tài)
28 show global status; 全局?jǐn)?shù)據(jù)庫狀態(tài)
29 show slave status\G; 查看主從數(shù)據(jù)庫狀態(tài)信息
30 13.查詢數(shù)據(jù)庫參數(shù)
31 show variables;
32 14.修改數(shù)據(jù)庫參數(shù)
33 show variables like 'max_connect%';
34 set global max_connect_errors = 1000;(重啟數(shù)據(jù)庫會(huì)失效,要在配置文件中修改)
35 15.查看當(dāng)前數(shù)據(jù)庫隊(duì)列
36 show processlist;
37 16.創(chuàng)建普通用戶并授權(quán)給某個(gè)數(shù)據(jù)庫
38 grant all on databasename.* to 'user1'@'localhost' identified by '123456';
39 17.查詢表數(shù)據(jù)
40 select * from mysql.db; //查詢?cè)摫碇械乃凶侄?/p>
41 select count(*) from mysql.user; //count(*)表示表中有多少行
42 select db,user from mysql.db; //查詢表中的多個(gè)字段
43 select * from mysql.db where host like '10.0.%';在查詢語句中可以使用萬能匹配 “%”
44 18.插入一行數(shù)據(jù)
45 insert into db1.t1 values (1, 'abc');
46 19.更改表的某一行數(shù)據(jù)
47 update db1.t1 set name='aaa' where id=1;
48 20.清空表數(shù)據(jù)
49 truncate table db1.t1;
50 21.刪除表
51 drop table db1.t1;
52 22.清空數(shù)據(jù)庫中的所有表(數(shù)據(jù)庫名是eab12)
53 mysql -N -s information_schema -e "SELECT CONCAT('TRUNCATE TABLE ',TABLE_NAME,';') FROM TABLES WHERE TABLE_SCHEMA='eab12'" | mysql -f eab12
54 23.刪除數(shù)據(jù)庫
55 drop database db1;
56 24.數(shù)據(jù)庫備份
57 mysqldump -uroot -p'yourpassword' mysql >/tmp/mysql.sql
58 25.數(shù)據(jù)庫恢復(fù)
59 mysql -uroot -p'yourpassword' mysql </tmp/mysql.sql
60 26.新建普通用戶
61 CREATE USER name IDENTIFIED BY 'ssapdrow';
62 27.更改普通用戶密碼
63 SET PASSWORD FOR name=PASSWORD('fdddfd');
64 28.查看name用戶權(quán)限
65 SHOW GRANTS FOR name;
66 29.腳本中執(zhí)行mysql命令
67 mysql -uuser -ppasswd -e"show databases"
68 echo "show databases"|mysql -uuser -ppassword
69 以下是執(zhí)行大量mysql語句采用的方式
70 mysql -uuser -hhostname -ppasswd <<EOF
71 mysql語句
72 EOF