溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

MySQL的編譯安裝及基礎(chǔ)操作流程

發(fā)布時間:2020-05-29 16:05:49 來源:網(wǎng)絡(luò) 閱讀:210 作者:三月 欄目:MySQL數(shù)據(jù)庫

不知道大家之前對類似MySQL的編譯安裝及基礎(chǔ)操作流程的文章有無了解,今天我在這里給大家再簡單的講講。感興趣的話就一起來看看正文部分吧,相信看完MySQL的編譯安裝及基礎(chǔ)操作流程你一定會有所收獲的。

一、mysql 5.7 安裝

--------------------------安裝mysql編譯環(huán)境--------------------------------------

yum -y install \

ncurses \

ncurses-devel \

bison \

cmake

--------------------------安裝mysql壓縮包--------------------------------------

useradd -s /sbin/nologin mysql

tar zxvf mysql-5.7.17.tar.gz -C /opt/

tar zxvf boost_1_59_0.tar.gz -C /usr/local/

cd /usr/local/

mv boost_1_59_0 boost

--------------------------mysql編譯安裝--------------------------------------

cd mysql-5.7.17/

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DSYSCONFDIR=/etc \

-DSYSTEMD_PID_DIR=/usr/local/mysql \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DWITH_BOOST=/usr/local/boost \

-DWITH_SYSTEMD=1

------注意:如果在CMAKE的過程中有報錯,當(dāng)報錯解決后,需要把源碼目錄中的CMakeCache.txt文件刪除,然后再重新CMAKE,否則錯誤依舊------------

make && make install

chown -R mysql.mysql /usr/local/mysql/

---------------------------修改mysql配置文件--------------------------------

vi /etc/my.cnf

[client]

port = 3306

default-character-set=utf8

socket = /usr/local/mysql/mysql.sock

[mysql]

port = 3306

default-character-set=utf8

socket = /usr/local/mysql/mysql.sock

[mysqld]

user = mysql

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

character_set_server=utf8

pid-file = /usr/local/mysql/mysqld.pid

socket = /usr/local/mysql/mysql.sock

server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

----------------------------------------修改環(huán)境變量-----------------------

chown mysql:mysql /etc/my.cnf

echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile

echo 'export PATH' >> /etc/profile

source /etc/profile

------------------------------------數(shù)據(jù)初始化------------------------------------

cd /usr/local/mysql/

bin/mysqld \

--initialize-insecure \

--user=mysql \

--basedir=/usr/local/mysql \

--datadir=/usr/local/mysql/data

-----------------------------------------啟動服務(wù)----------------------------------

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

systemctl daemon-reload

systemctl start mysqld

netstat -anpt | grep 3306

systemctl enable mysqld

mysqladmin -u root -p password "abc123" //給root賬號設(shè)置密碼為abc123提示輸入的是原始密碼。

mysql -u root -p

------------------------授權(quán)遠(yuǎn)程登錄-------------------------------------

grant all privileges on *.* to 'root'@'%' identified by 'abc123' with grant option;


二、mysql數(shù)據(jù)庫基本操作

--------------------------庫----------------------------

//創(chuàng)建數(shù)據(jù)庫 create database Myschool;

//查看數(shù)據(jù)庫 show databases;

//刪除數(shù)據(jù)庫 drop database Myschool;

//進(jìn)入數(shù)據(jù)庫 use Myschool;

---------------------------表---------------------------

//創(chuàng)建表 create table info (id int not null primary key auto_increment,name char(10) not null, score decimal(5,2),hobby int(2));

//刪除表 drop table info;

//查看表結(jié)構(gòu) desc info;

//查看Mycshool中的表 show tables;

//修改數(shù)據(jù)表名 alter table info rename to info7;

//多表查詢 select * from info inner join hob where info.hobby=hob.id;

              select info.name,ifo.score.hob.hobname from info inner join hob where info.hobby=hob.id;

//別名查詢 select i.name,i.score.h.hobname from info i inner join hob h where i.hobby=h.id;

//查詢生成新表 create table info2 select i.name,i.score.h.hobname from info i inner join hob h where i.hobby=h.id;

----------------------數(shù)據(jù)---------------------------

//查看info表中的數(shù)據(jù) select * from info;

//插入數(shù)據(jù) insert into info (id,name,score) values (5,'tianqi',80);

//篩選 條件 select * from info where id=6;

//修改更新信息 update info set score=75 where id=6;

//刪除信息 delete from info where name='test';

//添加字段 alter table info add hobby int(2);

//修改列名 alter table info rename column score to score2;

//修改字段的數(shù)據(jù)類型 alter table info modify score decimal(4,1);

//排序(升序/降序)select * from info where 1=1 order by score; 默認(rèn)升序

            select * from info where 1=1 order by score asc; 升序

            select * from info where 1=1 order by score desc; 降序

//分組  select * from info group by hobby

//聚合函數(shù)

           統(tǒng)計 count() 例:select count(*) from info2;

           平均值 avg() 例:select avg(score)from info2;


三、mysql索引與事務(wù)

索引創(chuàng)建方法:create index 索引名字 on 列的列表

例:create index id_index on info(id);

查詢索引:show index from info; show index from info \G;

刪除索引:drop index id_index on info;

創(chuàng)建唯一索引:create unique index id_index on info(id);

創(chuàng)建主鍵索引:alter table info add primary key(id);

添加字段: alter table info add column age int;

刪除字段:alter table info drop column age;

創(chuàng)建全文索引:create table info(descript TEXT,FULLTEXT(descript)); engine=MyISAM

多列索引:create index multi_index on info(name,adress);


事務(wù):一組操作共同執(zhí)行或者都不執(zhí)行,結(jié)果保持一致;

begin 開始 set autocommit=0 :禁止自動提交

commit 提交

rollback 回滾

savepoint s1; 定義回滾點

rollback to savepoint s1; 回滾到定義的回滾點

事務(wù)四個特性:

原子性,一致性,隔離性,持久性


視圖 數(shù)據(jù)庫中的虛擬表

作用: 一張表或者多表中的數(shù)據(jù)給不同的權(quán)限用戶提供訪問

create view score_view as select * from info where score > 80;


四、用戶管理

創(chuàng)建

create user ‘username’@‘host’ identified by 'passwd'

grant 權(quán)限 on 數(shù)據(jù)庫.表 to 用戶@主機(jī) identified by 密碼

查看

select user,authentication_string,host from user;

刪除

drop user 'lisi'@'localhost';

重命名

rename user 'zhangsan'@'localhost' to 'test'@'192.168.218.130';

密碼明文轉(zhuǎn)化成密文

select password('abc123');

create user ‘username’@‘host’ identified by password '*6691484EA6B50DDDE1926A220DA01FA9E575C18A';

更改用戶密碼

set password for 'test'@'192.168.218.130' = password('abc123');

忘記密碼(5.7)

systemctl stop mysqld

vim /etc/my.cnf

[mysqld]

skip-grant-tables

systemctl start mysqld

mysql

update mysql.user set authentication_string = password('abc123') where user = 'root';

賦權(quán)

grant 權(quán)限 on 數(shù)據(jù)庫.表 to 用戶@主機(jī) identified by 密碼;

撤銷權(quán)限

revoke 權(quán)限 on 數(shù)據(jù)庫.表 from 用戶@主機(jī);

查看權(quán)限

show grants for 用戶@主機(jī);

日志管理

vim /etc/my.cnf

[mysqld]

log-error=/usr/local/mysql/data/mysql_error.log #錯誤日志

general_log=ON #通用日志

general_log_file=/usr/local/mysql/data/mysql_general.log

log_bin=mysql-bin #二進(jìn)制日志(記錄所有操作)

查看二進(jìn)制文件

mysqlbinlog --no-defaults mysql-bin.00001

慢日志

slow_query_log=ON

slow_query_log_file=mysql-slow_query.log

long_query_time=1 #參照時間

看完MySQL的編譯安裝及基礎(chǔ)操作流程這篇文章,大家覺得怎么樣?如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI