linux下安装mysql

数据库mysql的Linux版本的安装过程就在下面了,请小伙伴们参考。

一、环境准备

实验环境:centos 7.5
数据库版本:5.6.41

二、 数据库安装

2.1 安装部分包

yum -y install numactl libaio*

2.2 下载

[root@localhost ~]# cd /usr/local
[root@localhost local]# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz

2.3 解压

[root@localhost local]# tar -zxvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz

2.4 复制

[root@localhost local]# cp -r mysql-5.6.41-linux-glibc2.12-x86_64 /usr/local/mysql

2.5  添加系统mysql组和mysql用户

[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -r -g mysql mysql

 2.6 安装数据库

创建mysql数据和日志存放目录
[root@localhost local]# cd /
[root@localhost /]# mkdir data
[root@localhost /]# cd data
[root@localhost data]# mkdir mysql
[root@localhost data]# cd mysql
[root@localhost mysql]# mkdir data
[root@localhost mysql]# mkdir log
[root@localhost mysql]# cd log
[root@localhost log]# touch error.log
[root@localhost log]# chown -R mysql:mysql /data/mysql/log
[root@localhost log]# chown -R mysql:mysql /data/mysql/data

切到mysql安装目录
[root@localhost local]# cd /usr/local/mysql

修改当前目录拥有者为mysql用户
[root@localhost mysql]# chown -R mysql:mysql ./

安装数据库
[root@localhost mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql

2.7 修改/etc/my.cnf文件

[root@localhost mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]# vim /etc/my.cnf
配置如下:
[mysqld]
user = mysql
port = 3306
autocommit = 1
server_id = 20180827
character-set-server=utf8
lower_case_table_names=1
basedir = /usr/local/mysql
datadir = /data/mysql/data
socket = /tmp/mysql.sock
pid-file = /data/mysql/data/mysqld.pid

# connection settings #
interactive_timeout=1800
wait_timeout=1800
max_connections =1000

# session memory settings #
read_buffer_size=16M
read_rnd_buffer_size=64M

# log settings #
log_error = /data/mysql/log/error.log
slow_query_log_file = /data/mysql/log/slow.log
log-bin=/data/mysql/log/mysql-bin
expire_logs_days=7
slow_query_log = 1
long-query-time = 1 #慢查询时间 超过1秒则为慢查询

# innodb settings #
innodb_log_buffer_size=64M
innodb_sort_buffer_size=2M
sort_buffer_size=64M
thread_cache_size=80

# replication settings #
master_info_repository = TABLE
relay_log_info_repository = TABLE
sync_binlog = 1
log_slave_updates
binlog_format=row
binlog_rows_query_log_events = 1
relay_log = relay.log
relay_log_recovery = 1
slave_skip_errors = ddl_exist_errors
slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'

replicate-ignore-db=mysql
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
replicate-ignore-db=test

 2.8 设置mysql自动启动

将服务文件拷贝到init.d下,并重命名为mysqld
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

修改/etc/init.d/mysqld文件
[root@localhost mysql]# vi /etc/init.d/mysqld
设置basedir和datadir的路径,配置如下:
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

赋予可执行权限
[root@localhost mysql]# chmod +x /etc/init.d/mysqld

 2.9 启动mysql服务并初始化密码

启动mysql服务
[root@localhost mysql]# service mysqld start
Starting MySQL.. SUCCESS!

配置环境变量(也可以用不配置环境变量,设置软链接)
[root@localhost mysql]# vi /etc/profile
加入以下内容:
PATH=/usr/local/mysql/bin:$Path
export PATH

使配置立即生效
[root@localhost mysql]# source /etc/profile

修改密码
[root@localhost mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 1
Server version: 5.6.41-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> set password for root@localhost = password('root');
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

重新登录
mysql> exit
Bye
[root@localhost mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 2
Server version: 5.6.41-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

 到这里数据库安装完成了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值