1.1源码安装MySQL-5.7

2022/7/31 2:52:46

本文主要是介绍1.1源码安装MySQL-5.7,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

MySQL-5.7源码安装(编译)

 

下载并解压mysql-5.7.26.tar.gz

[root@centos7 ~]#tar xf mysql-5.7.26.tar.gz

[root@centos7 ~]#cd mysql-5.7.26/

 

#安装依赖包

[root@centos7 mysql-5.7.26]#yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel

 

 

#安装boots

[root@centos7 mysql-5.7.26]#

wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

[root@centos7 mysql-5.7.26]# tar xf boost_1_59_0.tar.gz -C /usr/local

 

#cmake一下

[root@centos7 mysql-5.7.26]# cmake . \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.26 \

-DMYSQL_DATADIR=/usr/local/mysql-5.7.26/data \

-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.7.26/tmp/mysql.sock \

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/usr/local/boost_1_59_0 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITH_ZLIB=bundled \

-DWITH_SSL=system \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLE_DOWNLOADS=1 \

-DWITH_DEBUG=0

 

[root@centos7 mysql-5.7.26]# make && make install

 

 

 

 

创建mysql用户

[root@centos7 data]# useradd -r -s /sbin/nologin -d /data/mysql mysql

 

 

#创建数据存放目录

[root@centos7 mysql-5.7.26]# cd /usr/local

[root@centos7 /usr/local]# ln -s  /usr/local/mysql-5.7.26 /usr/local/mysql

[root@centos7 /usr/local]# mkdir /usr/local/mysql-5.7.26/{data,tmp}

[root@centos7 /usr/local]# touch /var/log/mysqld.log

[root@centos7 /usr/local]# chown -R mysql.mysql /usr/local/mysql-5.7.26

[root@centos7 /usr/local]# chown -R mysql.mysql /var/log/mysqld.log

 

#初始化

[root@centos7 /usr/local]#/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

 

#参数介绍:

  --initialize-insecure  #不安全初始化,即没有密码。

  --initialize  #安全初始化,会自动生成临时密码。在log-error里,查询 temporary password

  --user=mysql  #初始化用户

  --basedir=/service/mysql  #软件安装目录

  --datadir=/service/mysql/data  #数据存放位置

 

#编辑配置文件

[root@centos7 /usr/local]# vim /etc/my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

port=3306

socket=/usr/local/mysql/tmp/mysql.sock

character-set-server=utf8mb4

log-error=/var/log/mysqld.log

pid-file=/usr/local/mysql/tmp/mysqld.pid

 

[mysql]

socket=/usr/local/mysql/tmp/mysql.sock

 

[client]

socket=/usr/local/mysql/tmp/mysql.sock

 

#加入systemd管理

[root@centos7 /usr/local]# cp mysql/support-files/mysql.server /etc/init.d/mysqld

 

[root@centos7 /usr/local]# vim /usr/lib/systemd/system/mysqld.service

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=https://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

ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE = 5000

 

[root@centos7 /usr/local]# systemctl daemon-reload

[root@centos7 /usr/local]# systemctl start mysqld

 

#查询默认初始密码

[root@centos7 /usr/local]# grep 'temporary password' /var/log/mysqld.log

2021-09-24T01:38:06.444154Z 1 [Note] A temporary password is generated for root@localhost: z8oqda0;

 

 

 

添加PATH环境变量

[root@centos7 data]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

[root@centos7 data]# . /etc/profile.d/mysql.sh

 

 

 

#添加PATH后,测试连接

[root@centos7 /usr/local]# mysql -uroot -p

 

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 4

yp这里没有找到密码怎么办

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

⒈打开配置文件/etc/my.cnf,然后在里面找到 [mysqld] 这一项,然后在该配置项下添加skip-grant-tables 这个配置,然后保存文件。

⒉重启mysql服务:systemctl restart mysqld

⒊接着就可以免密登录了:敲入 mysql -u root -p 命令然后回车,当需要输入密码时,直接按enter键,便可以不用密码登录到数据库当中。

⒋重置密码:

use mysql;

update user set authentication_string=password(‘password’) where user=‘root’ and host=‘localhost’;

flush privileges;

 

说明:执行sql语句的时候,如果出现ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement. 则需要先执行一下

 

flush privileges.

 

⒌退出mysql:quit

 

 

⒍重启mysql服务: service mysql restart

 

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

登录进去后改密码,把配置文件改回来

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

 

mysql> update user set authentication_string =password('Mmagedu0!') where user='root' and host='locaclhost';

 

mysql> flush privileges;

 

mysql>exit;

 

 

 

 

安全固化mysql,输密码的输密码,其它一路y下来

 

[root@centos7 data]# mysql_secure_installation

 

Securing the MySQL server deployment.

 

Enter password for user root:

 

The existing password for the user account root has expired. Please set a new password.

 

New password:

 

Re-enter new password:

Sorry, passwords do not match.

 

New password:

 

Re-enter new password:

 

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

 

Press y|Y for Yes, any other key for No: y

 



这篇关于1.1源码安装MySQL-5.7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程