MySQL的编译安装及基础操作流程

不知道大家之前对类似MySQL的编译安装及基础操作流程的文章有无了解,今天我在这里给大家再简单的讲讲。感兴趣的话就一起来看看正文部分吧,相信看完MysqL的编译安装及基础操作流程你一定会有所收获的。

一、MysqL 5.7 安装

--------------------------安装MysqL编译环境--------------------------------------

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的过程中有报错,当报错解决后,需要把源码目录中的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

----------------------------------------修改环境变量-----------------------

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

------------------------------------数据初始化------------------------------------

cd /usr/local/MysqL/

bin/MysqLd \

--initialize-insecure \

--user=MysqL \

--basedir=/usr/local/MysqL \

--datadir=/usr/local/MysqL/data

-----------------------------------------启动服务----------------------------------

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账号设置密码为abc123提示输入的是原始密码。

MysqL -u root -p

------------------------授权远程登录-------------------------------------

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

二、MysqL数据库基本操作

--------------------------库----------------------------

//创建数据库 create database Myschool;

//查看数据库 show databases;

//删除数据库 drop database Myschool;

//进入数据库 use Myschool;

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

//创建表 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;

//查看表结构 desc info;

//查看Mycshool中的表 show tables;

//修改数据表名 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;

----------------------数据---------------------------

//查看info表中的数据 select * from info;

//插入数据 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;

//修改字段的数据类型 alter table info modify score decimal(4,1);

//排序(升序/降序)select * from info where 1=1 order by score; 认升序

            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

//聚合函数

           统计 count() 例:select count(*) from info2;

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

三、MysqL索引与事务

索引创建方法: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;

创建唯一索引:create unique index id_index on info(id);

创建主键索引:alter table info add primary key(id);

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

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

创建全文索引:create table info(descript TEXT,FULLTEXT(descript)); engine=MyISAM

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

事务:一组操作共同执行或者都不执行,结果保持一致;

begin 开始 set autocommit=0 :禁止自动提交

commit 提交

rollback 回滚

savepoint s1; 定义回滚点

rollback to savepoint s1; 回滚到定义的回滚点

事务四个特性:

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

视图 数据库中的虚拟表

作用: 一张表或者多表中的数据给不同的权限用户提供访问

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

四、用户管理

创建

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

grant 权限 on 数据库.表 to 用户@主机 identified by 密码

查看

select user,authentication_string,host from user;

删除

drop user 'lisi'@'localhost';

重命名

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

密码明文转化成密文

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';

赋权

grant 权限 on 数据库.表 to 用户@主机 identified by 密码;

撤销权限

revoke 权限 on 数据库.表 from 用户@主机;

查看权限

show grants for 用户@主机;

日志管理

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 #二进制日志(记录所有操作)

查看二进制文件

MysqLbinlog --no-defaults MysqL-bin.00001

慢日志

slow_query_log=ON

slow_query_log_file=MysqL-slow_query.log

long_query_time=1 #参照时间

看完MysqL的编译安装及基础操作流程这篇文章,大家觉得怎么样?如果想要了解更多相关,可以继续关注我们的行业资讯板块。

相关文章

MySQL 死锁 是指两个或多个事务互相等待对方持有的锁,从而导...
在MySQL中,InnoDB引擎通过Next-Key Locking技术来解决幻读问...
在数据库事务管理中,Undo Log 和 Redo Log 是两种关键日志,...
case when概述 sql语句中的case语句与高级语言中的switch语句...
其实很简单,只是为了忘记,做个记录,用的时候方便。 不管是...
1.进入服务,找到mysql服务,在属性里找到mysql的安装路径 2...