码迷,mamicode.com
首页 > 系统相关 > 详细

linux环境下的安装

时间:2020-04-30 09:57:55      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:ali   上传   $path   sbin   lock   err   rip   glibc   模式   

准备

系统 :CentOS-7-x86_64-DVD-1810.iso
数据库版本:mysql-5.7.26

清理历史环境

root@mysql_01 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@mysql_01 ~]# yum remove mariadb-libs -y

创建用户和组

[root@mysql_01 ~]# useradd mysql -s /sbin/nologin
[root@mysql_01 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)

创建相关目录

# 创建软件目录
mkdir -p /app/database/
# 创建数据目录
mkdir -p /data/3306
# 创建日志目录
mkdir -p /binlog/3306

设置权限

chown -R mysql.mysql /app/ /data/ /binlog/

上传软件并解压做软链接

[root@mysql_01 ~]# cd /app/database/
[root@mysql_01 database]# ls
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@mysql_01 database]# tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@mysql_01 database]# ll
total 629756
drwxr-xr-x 9 root root       129 Apr 29 13:50 mysql-5.7.26-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 644869837 Apr 29 13:49 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@mysql_01 database]# ln -s mysql-5.7.26-linux-glibc2.12-x86_64 mysql
[root@mysql_01 database]# ll
total 629756
lrwxrwxrwx 1 root root        35 Apr 29 13:51 mysql -> mysql-5.7.26-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root       129 Apr 29 13:50 mysql-5.7.26-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 644869837 Apr 29 13:49 mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@mysql_01 database]# cd mysql
[root@mysql_01 mysql]# ll
total 36
drwxr-xr-x  2 mysql mysql  4096 Apr 29 13:50 bin
-rw-r--r--  1 mysql mysql 17987 Apr 13  2019 COPYING
drwxr-xr-x  2 mysql mysql    55 Apr 29 13:50 docs
drwxr-xr-x  3 mysql mysql  4096 Apr 29 13:50 include
drwxr-xr-x  5 mysql mysql   230 Apr 29 13:50 lib
drwxr-xr-x  4 mysql mysql    30 Apr 29 13:50 man
-rw-r--r--  1 mysql mysql  2478 Apr 13  2019 README
drwxr-xr-x 28 mysql mysql  4096 Apr 29 13:50 share
drwxr-xr-x  2 mysql mysql    90 Apr 29 13:50 support-files

设置环境变量

vim /etc/profile
# 添加一行
export PATH=/app/database/mysql/bin:$PATH

# 生效配置
source /etc/profile

# 使用mysql -V打印出数据库版本说明环境变量配置成功
[root@mysql_01 mysql]# mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for linux-glibc2.12 (x86_64) using  EditLine wrapper

初始化系统库表

[root@mysql_01 mysql]# mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/

# 报错
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

# 解决
[root@mysql_01 mysql]# yum install -y libaio-devel

# 再次运行
[root@mysql_01 mysql]# mysqld --initialize-insecure --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/

5.7 初始化方式

mysqld --initialize

  • 初始化完成后,会生成12位临时密码,但是必须在使用mysql之前重置这个密码
  • 密码管理使用严格模式(密码复杂度、长度)

mysqld --initialize-insecure

  • 可以直接使用 mysql 访问,无需密码

5.6 初始化方式

/app/database/mysql/scripts/mysql_install_db --user=mysql --basedir=/app/database/mysql --datadir=/data/3306/

配置文件设置

cat >/etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/app/database/mysql 
datadir=/data/3306/
server_id=6
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
EOF

准备 MySQL 启动脚本

[root@mysql_01 app]# cd /app/database/mysql/support-files
# 拷贝MySQL启动脚本至系统软件管理目录中
[root@mysql_01 support-files]# cp mysql.server /etc/init.d/mysqld
# centos 6
[root@mysql_01 ~]# service mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to ‘/data/3306/mysql_01.err‘.
 SUCCESS! 
 
# centos 7
[root@mysql_01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@mysql_01 ~]# systemctl start mysqld
[root@mysql_01 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

linux环境下的安装

标签:ali   上传   $path   sbin   lock   err   rip   glibc   模式   

原文地址:https://www.cnblogs.com/qiuxirufeng/p/12806473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!