乐趣区

关于mysql:Linux系统源码安装mysql

MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,属于 Oracle 旗下产品。MySQL 是最风行的关系型数据库管理系统之一,在 WEB 利用方面,MySQL 是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件之一。

上面应用 centos7 装置 mysql

1、首先去官网下载安装包
http://mirrors.sohu.com/mysql/

2、yum 装置环境

yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

3、添加程序用户
useradd -s /sbin/nologin mysql

4、解压安装包
tar xf mysql-boost-5.7.20.tar.gz

5、cd 到 mysql 的配置目录中,而后编译装置
cd mysql-5.7.20/

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=boost \
-DWITH_SYSTEMD=1

make && make install

这个过程十分十分慢,请急躁期待(取决于你的电脑性能)

6、加权限

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

7、批改配置文件
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

8、批改权限
chown mysql:mysql /etc/my.cnf

9、让其能够辨认 mysql 中的命令
echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH’ >> /etc/profile
echo ‘export PATH’ >> /etc/profile

source /etc/profile

10、初始化数据库
cd /usr/local/mysql/

bin/mysqld \
–initialize-insecure \
–user=mysql \
–basedir=/usr/local/mysql \
–datadir=/usr/local/mysql/data

11、复制启动脚本模板
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

12、刷新启动脚本并启动

systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306
systemctl enable mysqld

13、给 root 设置明码
mysqladmin -u root -p password “abc123”

14、登录数据库
mysql -u root -p

15、受权近程登录
grant all privileges on . to ‘root’@’%’ identified by ‘abc123’ with grant option;
flush privileges;

退出移动版