一:MySQL:
安裝:
資料庫一鍵安裝:yum
yum -y install wget
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm (rpm安裝)
yum -y install yum-utils
vim /etc/yum.repos.d/mysql-community.repo
yum install -y mysql-community-server 啟動服務
systemctl start mysqld 設定開機啟動
grep password /var/log/mysqld.log (過濾密碼)
免密登錄:
vim /etc/my.cnf 添加skip-grant-tables
systemctl restart mysqld
mysql
use mysql;
update user set
authentication_string=password(‘QianFeng@123’) where user=‘root’;
flush privileges;
\q (退出)
vim /etc.my.cnf 注釋掉 skip-grant-table
mysql -uroot -p’QianFeng@123’
MySQL修改密碼的四種方法:
root修改自己的密碼
方法1:mysqladmin -uroot -p’123’ password ‘new_passwd’ #123是舊的密碼:
方法2:set passwd=‘new_passwd’
方法三:grep password /var/log/mysqld.log (過濾密碼)
vim /etc/my.cnf 添加skip-grant-tables
systemctl restart mysqld
方法四:進去 mysql
use mysql;
update user set
authentication_string=password(‘QianFeng@123’) where user=‘root’;
flush privileges;
\q (退出)
vim /etc.my.cnf 注釋掉 skip-grant-table
mysql -uroot -p'QianFeng@123'
請說說你所知道的mysql的存盤引擎和默認的存盤引擎分別都有和都是什么?
1, InnoDB存盤引擎
2、MyISAM存盤引擎
3、MEMORY記憶體型引擎
卸載mysql 安裝新的,必須洗掉 /etc/my.cnf 和 /var/lib/mysql
不然下次安裝,還是舊的資料庫,密碼的話還是不變的
洗掉 yum -y remove mysql-server
pkill mysql
yum - y install mysql-server
資料型別:
1,int (整數)
2,float (小數)
3,char vchar
4,enum
5,date time datetime
6,year
資料庫的簡單的操作:
mysql -uroot -p’QianFeng@123’ 進去
show database; 查看資料庫
create database chen; 創建資料庫
use chen; 使用這個資料庫
show database; 查看資料庫
select database(); 查看當前所在的庫
create table test1(age tinyint,number int); 創建兩個表 表明它的資料型別
desc test1; 查看表結構
insert into values(30,88); 輸入內容
select * from test1; 查看內容
alter table t3 add (chinese int(10),english int(10));添加內容
drop table 表名:
drop database 庫名:
表的完整性的約束:
primary 主鍵
foreign 外鍵
定義的;兩種方式:
1 表存在,添加約束
alter table t7 add primary key(hostname)
2 表不存在,創建表并且指定約束
create table t9(hostname char(20),ip char(150),primary key(hostname))
洗掉主鍵:alter table tab_name drop primary key;
mysqladmin -u root -p’QianFeng@123’ password ‘ZhaoHan@123’ 修改密碼
創建資料庫中的表
float
create table test4(float_test float(5.2).);
char vchar
create table t8(c char(5),v varchar(12));
enum
create table t101(name enum(‘tom’,‘jim’));
date time datetime
create table test_time(d date,t time,dt datetime);
year
create table t3(born_year year);
MYSQL資料庫的CPU突然飆到500%,咋處理
1,top查看那個埠占用的cpu是最多的
2,show processeslist查看是否是由于大量的并發,鎖引起的負載問題
3,查看慢查詢,找出執行長的sql陳述句,是否走索引?要進行sql陳述句的優化
4,是否快取失效
5,mysql 進行互動使用了哪些協議?埠使用的是3306
1,tcp/ip
2,unix Socket協議------socket是一種內部行程通信的形式被用于在相同主機上行程行程間的雙向的通信連接點,
單表查詢:
簡單查詢:select id,name,sex from employee5;
有條件查詢:where
mysql> select id,name from employee5 where id<=3;
mysql> select id,name,salary from employee5 where salary>2000;
統計數量查詢:select count(*) from employee5;
索引:index
在創建表的時候指定
create table student1(id int not null, name varchar(100) not null, birthdy date, sex char(1) not null, index nameindex (name(50)));
表創建結束的時候創建索引
create table student2(id int not null, name varchar(100) not null, birthday date, sex char(1) not null);
create index nameindex on student2(name(50));
權限管理:
本地登錄: mysql -uroot -p …
遠程登錄 mysql -h 192.168.246.253 -P 3306 -uroot -p(密碼)
客戶端語法:mysql -h ip地址 -P埠號-u 用戶名-p 密碼 :如果沒有改埠號就不用-P指定埠
創建用戶:create user tom@‘lacalhost’ identified by ‘qf@123’;創建用戶并且設定密碼
% 所有
修改權限:grant all on . to ‘user3’@‘localhost’;
修改表以后需要重繪權限: flush privileges;
grant 權限串列 on 庫名.表名 to ‘用戶名’@'客戶端主機’identified BY ‘Qf@123’;
注意:root授權的時候千萬不要給予 .(所有庫下面的所有表) web.*(web庫下面的所有的表) web.stu_info(web庫下面的stu_info表)
授權 on(MySQL.user) mysql.db mysql.tables_priv
授權:grant all on 庫和表名 to u1@‘ip’ identified by “密碼”; 創建用戶以及設定權限是一體的
select * from mysql.user where user=‘u1’\G
select * from mysql.db where user=‘u1’\G
select * from mysql.tables_priv where user=‘u1’\G
root修改自己的密碼
方法1:mysqladmin -uroot -p’123’ password ‘new_passwd’ #123是舊的密碼:
方法2:set passwd=‘new_passwd’
root修改其他用戶的密碼:
use mysql
set passwd for user3@‘locaohost’=‘new_passwd’
洗掉用戶:drop ‘user3’@‘localhost’;
delete from mysql.user where user=‘tom’ AND host=‘localhost’;
日志管理: 錯誤日志 /var/log/mysqld.log
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/235558.html
標籤:其他
上一篇:root用戶密碼丟失的解決方法
下一篇:MYSQL資料定義功能(DDL)
