linux基于二进制的格式安装mysql5.7或8.0,推荐

二进制包文件可在myql官网下载
https://downloads.mysql.com/archives/community/
步骤一:创建mysql用户名和用户组

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

步骤二:准备二进制程序

[root@centos7 local]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/
[root@centos7 local]# ln -sv mysql-5.7.31-linux-glibc2.12-x86_64/ mysql
[root@centos7 local]# chown -Rv mysql.mysql mysql

步骤三、编辑配置文件

[root@centos7 ~]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
skip_name_resolve = on
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid

[client]
socket=/data/mysql/mysql.sock

步骤四、生成环境变量

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

步骤五、生成mysql数据库

[root@centos7 ~]# mysqld --initialize --user=mysql --datadir=/data/mysql

步骤六、加载启动程序

[root@centos7 support-files]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos7 support-files]# chkconfig --add mysqld
[root@centos7 support-files]# service mysqld start
Starting MySQL. SUCCESS! 

步骤七、修改root口令

[root@centos7 support-files]# 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: 

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

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

验证:

[root@centos7 support-files]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> status
--------------
mysql  Ver 14.14 Distrib 5.7.31, for linux-glibc2.12 (x86_64) using  EditLine wrapper

Connection id:		7
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.31 MySQL Community Server (GPL)
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/data/mysql/mysql.sock
Uptime:			5 min 0 sec

Threads: 1  Questions: 16  Slow queries: 0  Opens: 113  Flush tables: 1  Open tables: 106  Queries per second avg: 0.053
--------------

mysql> 

总结:5.7和8.0生成数据库文件的命令是一样的。二进制包文件安装时比较快的,推荐
创建mysql的软连接便于后期进行mysql数据库进行版本升级。

猜你喜欢

转载自blog.csdn.net/weixin_50904580/article/details/111565564