linux mysql编译安装mysql_【MySQL安装】Linux下安装MySQL(预编译)

预编译方式安装MySQL

一、环境说明

操作系统:Redhat Linux 7.2

MySQL版本:5.7

安装介质:mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

二、安装MySQL软件

1.创建用户和组

# groupadd mysql

# useradd -g mysql -d /home/mysql mysql

# passwd mysql

2.上传压缩包到/usr/local/目录,解压

# cd /usr/local/

# tar -xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

解压后会生成一个mysql-5.7.25-linux-glibc2.12-x86_64的文件夹

3.创建软链接

# ln -s mysql-5.7.25-linux-glibc2.12-x86_64 mysql

三、初始化MySQL数据库

1.创建目录

# cd /usr/local/mysql

# mkdir mysql-files

# chmod 750 mysql-files/

2.初始化数据库

# cd /usr/local/mysql

# chown -R mysql:mysql .

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

注:basedir:指定MySQL的安装目录

datadir:指定MySQL的数据文件目录

2020-03-17T07:44:05.186790Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-03-17T07:44:05.629460Z 0 [Warning] InnoDB: New log files created, LSN=45790

2020-03-17T07:44:05.709511Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2020-03-17T07:44:05.773460Z 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: 140c9551-6823-11ea-ae76-0050563016cd.

2020-03-17T07:44:05.774908Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2020-03-17T07:44:05.776860Z 1 [Note] A temporary password is generated for

root@localhost: nwV/pWg:p5ko

(上面字体就是初始root密码)

# bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

Generating a 2048 bit RSA private key

.........................................................................+++

.........................................................................+++

writing new private key to 'ca-key.pem'

-----

Generating a 2048 bit RSA private key

.........................................................................+++

...............+++

writing new private key to 'server-key.pem'

-----

Generating a 2048 bit RSA private key

.......................................+++

.+++

writing new private key to 'client-key.pem'

-----

# chown -R root .

# chown -R mysql data mysql-files/

3.建立MySQL配置文件my.cnf

(my.conf文件已经有了)

# mv /etc/my.cnf /etc/my.cnf.bak

# vi /etc/my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

4.启动MySQL

方法一:使用mysqld_safe(手动启动)

# bin/mysqld_safe --user=mysql &

方法二:使用mysql.server脚本(将mysqld添加到服务中)

# cd /usr/local/mysql

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

# chkconfig --add mysqld

# chkconfig mysqld on

# service mysqld start

Starting MySQL. SUCCESS!

[1]+ Done bin/mysqld_safe --user=mysql

5.查看MySQL进程

# ps -ef|grep mysql

mysql 7138 7024 0 08:28 ? 00:00:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql.err --pid-file=/usr/local/mysql/data/mysql.pid

注:plugin-dir:插件目录

log-error:错误日志

pid-file:pid文件

凡是没有指定目录的,都是放在data目录下

6.修改环境变量

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

# source /etc/profile

7.登录mysql

# mysql -uroot -p'nwV/pWg:p5ko'

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 5.7.25

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>

8.重置root密码

mysql> alter user root@'localhost' identified by 'P@ssw0rd';

(可以尝试重新登录)

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

9.如果需要重新初始化[可选]

# service mysqld stop

# rm -rf /usr/local/mysql/data/

# cd /usr/local/mysql

# chown -R mysql:mysql .

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

# bin/mysql_ssl_rsa_setup

# chown -R root.

# chown -R mysql data mysql-files

10.可以在操作系统层面改密码

# mysqladmin -u'root' -p'P@ssw0rd' password "qaq123"

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

上述警告忽略

---- end ----

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值