返回顶部

第一章 mysql源码安装

 

mysql源码安装(5.6.36)

 

 

 

一.安装依赖包

 

 

1安装依赖包

yum install -y ncurses-devel libaio-devel

 

2安装cmake

yum install cmake –y

 

3创建用户

useradd -s /sbin/nologin -M mysql
id mysql

 

二.下载mysql

 

1 下载网址:

https://downloads.mysql.com

 

 

 

 

三.编译安装

1解压 

[root@db2 tools]# pwd
/home/ysl/tools
[root@db2 tools]# tar -xf mysql-5.6.36.tar.gz 
[root@db2 tools]# cd mysql-5.6.36

 

 

2编译安装

 

cd mysql-5.6.36
cmake . -DCMAKE_INSTALL_PREFIX=/data/mysql-5.6.36 \
-DMYSQL_DATADIR=/data/mysql-5.6.36/data \
-DMYSQL_UNIX_ADDR=/data/mysql-5.6.36/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
make && make install
ln -s /data/mysql-5.6.36/ /data/mysql

 

 

 

 

 

 2.1 配置 mysql

# 软连接
[root@db2 mysql-5.6.36]# ln -s /data/mysql-5.6.36/ /data/mysql

# 拷贝配置文件到/etc下   
[root@db2 mysql-5.6.36]# cp support-files/my*.cnf  /etc/my.cnf 
cp: overwrite `/etc/my.cnf'? y

# 初始化数据库
[root@db2 mysql-5.6.36]# /data/mysql/scripts/mysql_install_db --basedir=/data/mysql/ --datadir=/data/mysql/data --user=mysql



# 创建关键目录并设置权限
[root@db2 mysql-5.6.36]# mkdir -p /data/mysql/tmp
[root@db2 mysql-5.6.36]# chown -R mysql.mysql  /data/mysql/

# 复制 启动文件
[root@db2 mysql-5.6.36]# cp support-files/mysql.server  /etc/init.d/mysqld

# 启动mysql
[root@db2 mysql-5.6.36]# chmod +x /etc/init.d/mysqld
 
#配置环境变量
[root@db2 mysql-5.6.36]# echo 'export PATH=/data/mysql/bin/:$PATH' >>/etc/profile

 

 

[root@db2 mysql]# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.36 Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

 

 

3修改配置文件

[root@db2 ~]# cat  /etc/my.cnf 
[mysqld]
datadir=/data/mysql/data
basedir=/data/mysql
socket=/data/mysql/tmp/mysql.sock
port=3306
server_id=10
log-error=/var/log/mysql.log
log-bin=/data/mysql/data/mysql-bin
binlog_format=row
skip_name_resolve

[mysql]
socket=/data/mysql/tmp/mysql.sock

 

 

 

4 mysql启动和关闭

 

4.1 启动mysql

数据库的启动流程

mysql.server ------>mysqld_safe------->mysqld

 

启动:
[root@db02 ~]# /etc/init.d/mysqld start
或者:
[root@db02 ~]# /data/mysql/bin/mysqld_safe &

 

关闭:
[root@db02 ~]# mysqladmin -uroot -p123456 shutdown
或者:
[root@db02 ~]# /etc/init.d/mysqld stop

 

5 设置密码

 

① mysql root 密码为空时的设置

/data/mysql-5.6.36/bin/mysqladmin -uroot password "123456"
/data/mysql-5.6.36/bin/mysql  -uroot -p123456

 

mysqladmin  -u root -p112233  password '123456';
mysqladmin     -uroot -pold_pwd   password "new_pwd"

 

 

②   登录mysql再设置 

mysql> use mysql
Database changed
mysql> set password for root@localhost=password("123123");
Query OK, 0 rows affected (0.00 sec)

 

③ 登录mysql再设置

mysql> use mysql
Database changed
mysql> update user set password=password("123456") where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)

 

 

6 设置mysql 开机启动

[root@db2 tmp]# chkconfig --add mysqld
[root@db2 tmp]# chkconfig | grep mysql 
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

 

7 配置环境变量

echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile 

source /etc/profile

 


知识简述:

1. 简述mysql数据库支持的安装方式:

  yum安装    源码安装   二进制安装

2 简述mysql_install_db命令的查用参数:

   mysql_install_db  是初始化的命令

  mysql_install_db  --basedir=/data/mysql/   --datadir=/data/mysql/data   --user=mysql

           basedir 安装路径    datadir 数据库的存放路径   

 

posted on 2019-05-21 17:32  augustyang  阅读(250)  评论(0编辑  收藏  举报

导航