首页 资讯频道 互联频道 智能频道 网络 数据频道 安全频道 服务器频道 存储频道

在 Linux 下如何对数据库 MySQL 8.0 进行安装配置?

2020-09-27 16:08:54 来源 : 马哥Linux运维公众号

1、编译安装MySQL8.0

版本信息

#cat/etc/redhat-release

CentOSLinuxrelease7.5.1804(Core)

安装依赖包

yum-yinstallwgetcmakegccgcc-c++ncursesncurses-devellibaio-developensslopenssl-devel

rpm-qa|greplibaio

yuminstalllibaiolibaio-devel

下载源码包

wgethttps://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz

创建用户和建立数据目录并赋予用户目录权限

groupaddmysql

useradd-r-gmysql-s/sbin/nologinmysql

mkdir-p/usr/local/mysql

mkdir-p/data/mysql

chown-Rmysql.mysql/usr/local/mysql

chown-Rmysql.mysql/data/mysql

chmod-R755/usr/local/mysql/

chmod-R755/data/mysql/

解压并开始安装

tar-zxfmysql-boost-8.0.12.tar.gz

配置

cdmysql-8.0.12

cmake.-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_DATADIR=/data/mysql\

-DSYSCONFDIR=/etc\

-DMYSQL_TCP_PORT=3306\

-DWITH_BOOST=~/mysql-8.0.12/boost\

-DDEFAULT_CHARSET=utf8\

-DDEFAULT_COLLATION=utf8_general_ci\

-DENABLED_LOCAL_INFILE=ON\

-DWITH_INNODB_MEMCACHED=ON\

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_FEDERATED_STORAGE_ENGINE=1\

-DWITH_BLACKHOLE_STORAGE_ENGINE=1\

-DWITH_ARCHIVE_STORAGE_ENGINE=1\

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1\

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1

配置参数说明:

CMAKE_INSTALL_PREFIX :指定基础安装目录

MYSQL_DATADIR :指定数据目录

SYSCONFDIR=/etc :指定配置文件扫描目录

MYSQL_TCP_PORT :指定端口号

WITH_BOOST :指定boost所在目录

DEFAULT_CHARSET :指定默认字符集

DEFAULT_COLLATION :指定默认排序规则

ENABLED_LOCAL_INFILE=ON :是否为load data infile启用local

WITH_INNODB_MEMCACHED=ON :是否生成memcached共享库

编译&安装

make&&makeinstall

初始化数据库

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

建立配置文件

cat>/etc/my.cnf<

[client]

port=3306

socket=/tmp/mysql.sock

default-character-set=utf8

#user=root

#password=123

[mysqld]

server-id=1

#skip-grant-tables

port=3306

user=mysql

max_connections=200

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/data/mysql

pid-file=/data/mysql/mysql.pid

init-connect='SETNAMESutf8'

character-set-server=utf8

default-storage-engine=INNODB

log_error=/data/mysql/mysql-error.log

slow_query_log_file=/data/mysql/mysql-slow.log

[mysqldump]

quick

max_allowed_packet=16M

EOF

配置环境变量

echo"PATH=/usr/local/mysql/bin:$PATH">>/etc/profile

source/etc/profile

配置启动脚本

cp../mysql-8.0.12/support-files/mysql.server/etc/init.d/mysqld

vim/etc/init.d/mysqld

chmod+x/etc/init.d/mysqld

/etc/init.d/mysqldstart

centos7系统自启动脚本

cat/usr/lib/systemd/system/mysqld.service

[Unit]

Description=mysqlserverdaemon

Documentation=man:mysql(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

Type=notify

TimeoutSec=0

PermissionsStartOnly=true

ExecStart=/usr/local/mysql/bin/mysqld$MYSQLD_OPTS

LimitNOFILE=10000

Restart=always

RestartPreventExitStatus=1

Environment=MYSQLD_PARENT_PID=1

PrivateTmp=false

启动MySQL

systemctlstartmysqld.service

修改root密码:使用WITH指定认证方式

mysql-uroot

ALTERUSER'root'@'localhost'IDENTIFIEDWITHmysql_native_passwordBY'你的密码';

ALTERUSER'root'@'localhost'IDENTIFIEDWITHcaching_sha2_passwordBY'你的密码';

查看密码字段和加密方式

selecthost,user,authentication_string,pluginfromuser;

2、yum存储库安装MySQL

wgethttps://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

yumlocalinstallmysql80-community-release-el7-1.noarch.rpm

yumrepolistenabled|grep"mysql.*-community.*"

yumrepolistall|grepmysql

yuminstallmysql-community-server

systemctlenablemysqld

systemctlstartmysqld

netstat-lntup|grep3306

查看随机生成的密码

grep'temporarypassword'/var/log/mysqld.log

mysql-uroot-p

修改密码,密码必须要由大小写字母、数字和特性字符组成

alteruser'root'@'localhost'identifiedby'[email protected]';

selectversion();

关键词: Linux 数据库 MySQL 8.0

最近更新