# MySQL 单机安装
[TOC]
>说明:
本次只在bd00上安装了mysql
除了以下操作,其它操作均是在创建的bigdata用户操作
1.创建用户
2.关闭防火墙
3.卸载老软件
4.添加自启懂
### 关闭防火墙
```
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
```
### 检查是否安装NySQL,如果安装 卸载之
```
rpm -qa |grep mysql
yum remove mysql*
```
### 检查是否安装MariaDB,如果安装 卸载之(重要)
```
rpm -qa |grep mariadb
yum remove mariadb*
```
## 安装
### 添加用户
```
useradd bigdata
```
>如果添加过了就不用了
### 切换用户
```
su - bigdata
```
### 下载
```
wget http://uni.mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
```
### 解压
```
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
```
### 修改文件夹名
```
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
```
### 进入mysql目录
```
cd /home/bigdata/soft/mysql
```
### 创建my.conf
```
vim /home/bigdata/soft/mysql/my.cnf
```
```
[client]
port=3306
socket=/home/bigdata/soft/mysql/mysql.sock
[mysqld]
basedir=/home/bigdata/soft/mysql
datadir=/home/bigdata/soft/mysql/data
socket=/home/bigdata/soft/mysql/mysql.sock
user=bigdata
pid-file=/home/bigdata/soft/mysql/data/mysql.pid #进程id
[mysql]
socket=/home/bigdata/soft/mysql/mysql.sock
```
### 初始化
```
./bin/mysqld --defaults-file=/home/bigdata/soft/mysql/my.cnf \
--initialize \
--basedir=/home/bigdata/soft/mysql/ \
--datadir=/home/bigdata/soft/mysql/data/ \
--user=bigdata \
--socket=/home/bigdata/soft/mysql/mysql.sock
```
>实际效果如下,还有个密码?
```
[mysql@bd00 mysql]$ ./bin/mysqld --initialize --user=mysql \
> --basedir=/home/bigdata/soft/mysql/ \
> --datadir=/home/bigdata/soft/mysql/data/
2019-05-24T14:50:38.189220Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2019-05-24T14:50:38.189310Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2019-05-24T14:50:38.189429Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-24T14:50:38.508430Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-05-24T14:50:38.666223Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-05-24T14:50:38.776967Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4b918103-7e33-11e9-b47e-000c29034af1.
2019-05-24T14:50:38.778797Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-05-24T14:50:38.779456Z 1 [Note] A temporary password is generated for root@localhost: L#-ZlQ397_6m
[mysql@bd00 mysql]$
```
### 复制mysql.server
```
cp /home/bigdata/soft/mysql/support-files/mysql.server /home/bigdata/soft/mysql/mysql.server
```
### 修改mysqld
```
cd /home/bigdata/soft/mysql
vim mysql.server
```
```
basedir=/home/bigdata/soft/mysql
datadir=/home/bigdata/soft/mysql/data
```
### 添加环境变量
```
vi /home/bigdata/.bash_profile
```
```
export MYSQL_HOME=/home/bigdata/soft/mysql
export PATH="$PATH:$MYSQL_HOME/bin"
```
```
source /home/bigdata/.bash_profile
```
## 运维
### 启动
```
/home/bigdata/soft/mysql/mysql.server start
```
### 停止
```
/home/bigdata/soft/mysql/mysql.server stop
```
### 开机自启动
>本次是配合hadoop生态圈使用,比如HIVE使用,所以没有添加自启动
只需要把
`su - mysql -c "/home/bigdata/soft/mysql/mysql.server start"`
放到
`/etc/rc.d/rc.local`
即可
### 初次登陆
```
mysql -h127.0.0.1 -uroot -p
```
>输入密码后即可登录
### 修改用户密码
```
mysql> alter user 'root'@'localhost' identified by 'youpassword';
```
或者
```
mysql> set password=password("youpassword");
```
### 允许远程连接
%代表任何ip
```
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
```
刷新权限
```
mysql>flush privileges;
```
然后远程就能访问了
## 参考
[https://www.jb51.net/article/150079.htm](https://www.jb51.net/article/150079.htm)
[https://www.cnblogs.com/chinesern/p/9309853.html](https://www.cnblogs.com/chinesern/p/9309853.html)
- 前言
- 虚拟机
- 前言
- 入门指南
- 集群规划
- 常用网址
- Hadoop集群常用端口
- 安装
- HA 环境安装教程
- 创建用户
- 设置SSH无密码登录
- MySQL安装
- 安装java
- 安装zookeeper
- hadoop 安装
- Hadoop HA 安装
- hadoop详细维护命令
- 集群性能测试
- 启动
- hadoop使用案例
- 安装hbase
- hive
- server2
- HA+联邦集群安装
- 常用
- 常用知识点
- HDFS
- HDFS 架构
- MapReduce
- MapReduce 教程
- HBase使用手册
- 简介
- HBase入门
- 安装HBase
- HBase管理页面
- 和HBase交互
- HBase Shell快速入门
- HBase数据模型
- HBase Schema设计
- HBase架构
- HBase安全
- HBase Shell命令
- HBase JSON配置使用说明
- HBase API使用说明
- HBase API运行教程
- HBase SQL基础
- HIVE
- 附录
- 各种数据库
- 操作系统教程
- centos7.4三机准备
- 防火墙
- 软件安装
- 伪双击安装指南
- 操作系统准备