性能测试复习准备——linux环境下安装mysql8

mysql下载地址:https://dev.mysql.com/downloads/mysql/

 

 

 

 

 

 

下载完成后,把软件包上传到此目录下:/soft/mysql8/

 

并解压缩到指定目录下:/evir/mysql8/

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 在bin目录下执行初始化命令: ./mysqld --user=mysql --basedir=/evir/mysql8/mysql8030/ --datadir=/evir/mysql8/mysql8030/data/ --initialize

 

 

 

 

但是先要创建用户组: 

 

 

 

 

 

 

 

 data目录赋予权限:chmod -R 755 /evir/mysql8/mysql8030/data/

 

 

命令: ln -s “你的MySQL根目录/bin/mysql” /usr/bin ,这一步是为了能在任何地方通过用户名和密码登录MySQL

我的本地如下: ln -s /evir/mysql8/mysql8030//bin/mysql /usr/bin

 

 

 

 

 

 

 

 

 

 

 

修改mysql密码:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456sww#';

 

 

 

 

 

 

 

 vim  /etc/profile:

 

 

 

[mysqld]
port=3306
basedir=/evir/mysql8/mysql8030/ # MySQL根目录
datadir=/evir/mysql8/mysql8030/data/ # MySQL的data目录
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
symbolic-links=0


#解决“java.sql.SQLException: Expression #1 of ORDER BY clause is not in SELECT list,references column”
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

 

 

 

 

 

 

 

 

 

 

 

 

参考文档:https://blog.csdn.net/studio_1/article/details/128345934

 

 

一、先前往官网下载mysql8

下载地址:

https://dev.mysql.com/downloads/

 选择Linux

 

 

 

 

 

./mysqld --user=mysql --basedir=/usr/MYSQL/mysql-8.0.31 --datadir=/usr/MYSQL/mysql-8.0.31/data --lower-case-table-names=1 --initialize

 

 

 

[mysqld]
port=3306
basedir=/usr/MYSQL/mysql-8.0.31/  # MySQL根目录
datadir=/usr/MYSQL/mysql-8.0.31/data/  # MySQL的data目录
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
symbolic-links=0


#解决“java.sql.SQLException: Expression #1 of ORDER BY clause is not in SELECT list,references column”
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

参考文档2:https://huaweicloud.csdn.net/653f72328c4ad05cd82a9e3a.html?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTQ2NDMwLCJleHAiOjE2OTk3MDcwMjksImlhdCI6MTY5OTEwMjIyOSwidXNlcm5hbWUiOiJtMF82MTQ0MjYwNyJ9.ztpfna-epq2FT3AiuZShFNVvRAKgi5HBoEnP3A_6WdM

 

 

 

 

 

 

 

 

 

 

 

 

 

修改root密码

接下来修改root密码,将123456换成你的新密码 

别忘了结尾有个分号“;”

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

 

 然后刷新权限 使密码生效

flush privileges;

 

 

 

 

 

 

 

设置允许远程连接并生效

update user set host='%' where user='root';
 
flush privileges;

 

 

 

防火墙设置:

 firewall-cmd --add-port=3306/tcp --permanent

 firewall-cmd --reload

 

 

 查看防火墙端口开放状态

firewall-cmd --list-all

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

./mysqld --user=mysql --basedir=/evir/mysql8/mysql8030/ --datadir=/evir/mysql8/mysql8030/data/ --initialize




chown -R mysql.mysql /evir/mysql8/mysql8030/








[root@iZbp14cdvd1cf45cy90gqcZ bin]# groupadd mysql
[root@iZbp14cdvd1cf45cy90gqcZ bin]# useradd -g mysql mysql
[root@iZbp14cdvd1cf45cy90gqcZ bin]# chown -R mysql.mysql /evir/mysql8/mysql8030/
[root@iZbp14cdvd1cf45cy90gqcZ bin]# ./mysqld --user=mysql --basedir=/evir/mysql8/mysql8030/ --datadir=/evir/mysql8/mysql8030/data/ --initialize                                    2023-11-11T07:33:09.773158Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-11-11T07:33:09.773257Z 0 [System] [MY-013169] [Server] /evir/mysql8/mysql8030/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process 11409
2023-11-11T07:33:09.780954Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-11-11T07:33:12.109123Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-11-11T07:33:14.821697Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 


y/PK2Jhi79Np








[mysqld]
port=3306
basedir=/evir/mysql8/mysql8030/  # MySQL根目录
datadir=/evir/mysql8/mysql8030/data/  # MySQL的data目录
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
symbolic-links=0


#解决“java.sql.SQLException: Expression #1 of ORDER BY clause is not in SELECT list,references column”
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'





cp -a ./support-files/mysql.server /etc/init.d/mysql




chmod -R 755 /evir/mysql8/mysql8030/data/





ln -s /evir/mysql8/mysql8030//bin/mysql /usr/bin





ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456sww#';













[root@iZbp14cdvd1cf45cy90gqcZ /]# cd soft/
[root@iZbp14cdvd1cf45cy90gqcZ soft]# ls -alt
total 16
drwxr-xr-x   2 root root 4096 Nov 11 15:00 mysql8
drwxr-xr-x   4 root root 4096 Nov 11 14:00 .
dr-xr-xr-x. 21 root root 4096 Nov 11 10:04 ..
drwxr-xr-x   2 root root 4096 Nov 11 10:02 jdk8
[root@iZbp14cdvd1cf45cy90gqcZ soft]# cd mysql8/
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 461540
-rw-r--r-- 1 root root 472601216 Nov 11 15:05 mysql-8.2.0-linux-glibc2.28-x86_64.tar.xz
drwxr-xr-x 2 root root      4096 Nov 11 15:00 .
drwxr-xr-x 4 root root      4096 Nov 11 14:00 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# rm -rf mysql-8.2.0-linux-glibc2.28-x86_64.tar.xz
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 8
drwxr-xr-x 2 root root 4096 Nov 11 15:16 .
drwxr-xr-x 4 root root 4096 Nov 11 14:00 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 585364
-rw-r--r-- 1 root root 599400444 Nov 11 15:25 mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
drwxr-xr-x 2 root root      4096 Nov 11 15:22 .
drwxr-xr-x 4 root root      4096 Nov 11 14:00 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# cd /soft/mysql8/
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 585364
-rw-r--r-- 1 root root 599400444 Nov 11 15:25 mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
drwxr-xr-x 2 root root      4096 Nov 11 15:22 .
drwxr-xr-x 4 root root      4096 Nov 11 14:00 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# cd /evir/
[root@iZbp14cdvd1cf45cy90gqcZ evir]# ls -alt
total 16
drwxr-xr-x   2 root root 4096 Nov 11 15:15 mysql8
drwxr-xr-x   4 root root 4096 Nov 11 14:08 .
drwxr-xr-x   3 root root 4096 Nov 11 10:06 jdk8
dr-xr-xr-x. 21 root root 4096 Nov 11 10:04 ..
[root@iZbp14cdvd1cf45cy90gqcZ evir]# cd mysql8/
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 8
drwxr-xr-x 2 root root 4096 Nov 11 15:15 .
drwxr-xr-x 4 root root 4096 Nov 11 14:08 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# cd /soft/mysql8/
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 585364
-rw-r--r-- 1 root root 599400444 Nov 11 15:25 mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
drwxr-xr-x 2 root root      4096 Nov 11 15:22 .
drwxr-xr-x 4 root root      4096 Nov 11 14:00 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# tar -vxf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz  /evir/mysql8/
^C
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# tar -vxf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz -C /evir/mysql8/


解压……


[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# cd /evir/mysql8/
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 12
drwxr-xr-x 9 root root 4096 Nov 11 15:28 mysql-8.0.30-linux-glibc2.12-x86_64
drwxr-xr-x 3 root root 4096 Nov 11 15:27 .
drwxr-xr-x 4 root root 4096 Nov 11 14:08 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# mv mysql-8.0.30-linux-glibc2.12-x86_64/ mysql8030
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# ls -alt
total 12
drwxr-xr-x 3 root root 4096 Nov 11 15:28 .
drwxr-xr-x 9 root root 4096 Nov 11 15:28 mysql8030
drwxr-xr-x 4 root root 4096 Nov 11 14:08 ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8]# cd mysql8030/
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# ls -alt
total 324
drwxr-xr-x  3 root root    4096 Nov 11 15:28 ..
drwxr-xr-x  9 root root    4096 Nov 11 15:28 .
drwxr-xr-x  2 7161 31415   4096 Jul  7  2022 bin
drwxr-xr-x  6 7161 31415   4096 Jul  7  2022 lib
drwxr-xr-x 28 7161 31415   4096 Jul  7  2022 share
drwxr-xr-x  2 7161 31415   4096 Jul  7  2022 support-files
drwxr-xr-x  2 7161 31415   4096 Jul  7  2022 docs
drwxr-xr-x  3 7161 31415   4096 Jul  7  2022 include
drwxr-xr-x  4 7161 31415   4096 Jul  7  2022 man
-rw-r--r--  1 7161 31415 287624 Jul  7  2022 LICENSE
-rw-r--r--  1 7161 31415    666 Jul  7  2022 README
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# mkdir data
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# ls -alt
total 328
drwxr-xr-x 10 root root    4096 Nov 11 15:28 .
drwxr-xr-x  2 root root    4096 Nov 11 15:28 data
drwxr-xr-x  3 root root    4096 Nov 11 15:28 ..
drwxr-xr-x  2 7161 31415   4096 Jul  7  2022 bin
drwxr-xr-x  6 7161 31415   4096 Jul  7  2022 lib
drwxr-xr-x 28 7161 31415   4096 Jul  7  2022 share
drwxr-xr-x  2 7161 31415   4096 Jul  7  2022 support-files
drwxr-xr-x  2 7161 31415   4096 Jul  7  2022 docs
drwxr-xr-x  3 7161 31415   4096 Jul  7  2022 include
drwxr-xr-x  4 7161 31415   4096 Jul  7  2022 man
-rw-r--r--  1 7161 31415 287624 Jul  7  2022 LICENSE
-rw-r--r--  1 7161 31415    666 Jul  7  2022 README
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# cd bin
[root@iZbp14cdvd1cf45cy90gqcZ bin]# groupadd mysql
[root@iZbp14cdvd1cf45cy90gqcZ bin]# useradd -g mysql mysql
[root@iZbp14cdvd1cf45cy90gqcZ bin]# chown -R mysql.mysql /evir/mysql8/mysql8030/
[root@iZbp14cdvd1cf45cy90gqcZ bin]# ./mysqld --user=mysql --basedir=/evir/mysql8/mysql8030/ --datadir=/evir/mysql8/mysql8030/data/ --initialize             2023-11-11T07:33:09.773158Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider s it' is deprecated and will be removed in a future release.
2023-11-11T07:33:09.773257Z 0 [System] [MY-013169] [Server] /evir/mysql8/mysql8030/bin/mysqld (mysqld 8.0.30) initializing of server in progress as process
2023-11-11T07:33:09.780954Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-11-11T07:33:12.109123Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-11-11T07:33:14.821697Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: y/PK2Jhi79Np
[root@iZbp14cdvd1cf45cy90gqcZ bin]# ^C
[root@iZbp14cdvd1cf45cy90gqcZ bin]# vim /etc/my.cnf
[root@iZbp14cdvd1cf45cy90gqcZ bin]# cd ..
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# cp -a ./support-files/mysql.server /etc/init.d/mysql
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# chmod +x /etc/init.d/mysql
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# chkconfig --add mysql
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# chmod -R 777 /evir/mysql8/mysql8030/data/
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# vim /etc/my.cnf
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# service mysql start
Starting MySQL.Logging to '/evir/mysql8/mysql8030/data/iZbp14cdvd1cf45cy90gqcZ.err'.
.                                                          [  OK  ]
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# service mysql status
MySQL running (16326)                                      [  OK  ]
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# ln -s /usr/MYSQL/mysql-8.0.31/bin/mysql /usr/bin
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# mysql -uroot -p
-bash: mysql: command not found
[root@iZbp14cdvd1cf45cy90gqcZ mysql8030]# cd /usr/bin
[root@iZbp14cdvd1cf45cy90gqcZ bin]# rm -rf /usr/bin/mysql
[root@iZbp14cdvd1cf45cy90gqcZ bin]# ln -s /evir/mysql8/mysql8030//bin/mysql /usr/bin
[root@iZbp14cdvd1cf45cy90gqcZ bin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> use mysql
No connection. Trying to reconnect...
Connection id:    9
Current database: *** NONE ***

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> LTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456sww#';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LNTIFIED WITH mysql_native_password BY '123456sww#'' at line 1
mysql> flush privileges;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456sww#';
Query OK, 0 rows affected (0.00 sec)

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> show tables;
+------------------------------------------------------+
| Tables_in_mysql                                      |
+------------------------------------------------------+
| columns_priv                                         |
| component                                            |
| db                                                   |
| default_roles                                        |
| engine_cost                                          |
| func                                                 |
| general_log                                          |
| global_grants                                        |
| gtid_executed                                        |
| help_category                                        |
| help_keyword                                         |
| help_relation                                        |
| help_topic                                           |
| innodb_index_stats                                   |
| innodb_table_stats                                   |
| password_history                                     |
| plugin                                               |
| procs_priv                                           |
| proxies_priv                                         |
| replication_asynchronous_connection_failover         |
| replication_asynchronous_connection_failover_managed |
| replication_group_configuration_version              |
| replication_group_member_actions                     |
| role_edges                                           |
| server_cost                                          |
| servers                                              |
| slave_master_info                                    |
| slave_relay_log_info                                 |
| slave_worker_info                                    |
| slow_log                                             |
| tables_priv                                          |
| time_zone                                            |
| time_zone_leap_second                                |
| time_zone_name                                       |
| time_zone_transition                                 |
| time_zone_transition_type                            |
| user                                                 |
+------------------------------------------------------+
37 rows in set (0.00 sec)

mysql> select * from usr;
ERROR 1146 (42S02): Table 'mysql.usr' doesn't exist
mysql>

 

 

 

 

 

 

 

参考博客:https://blog.csdn.net/weixin_39561004/article/details/114339330

 

mysql.user的作用_mysql通过mysql_install_db初始化数据目录时使用--user选项的作用是什么?...

 

 

需求描述:

mysql数据库通过mysql_install_db初始化数据目录时,使用了--user选项,这里记录下该参数的作用

 

参数解释:

1.--user的作用:就是以哪个操作系统用户来执行mysqld进程(使用哪个用户来运行mysql server)

 

 

2.比如,指定了--user=mysql之后,那么通过mysqld创建的文件或者目录都是被mysql用户拥有的(mysql创建的文件,目录的用户权限是mysql),即相当于是mysql用户创建的文件.

 

 

3.在初始化数据目录时,如果在root下执行mysql_install_db脚本需要指定--user选项,如果已经登录到了mysql这个系统用户下,则不需要指定,当前用户就是mysql服务器要运行的用户环境.

 

 

测试过程:

1.使用--user=mysql初始化数据目录后,查看创建的data目录的权限——备注:data目录的用户和用户组都是mysql.

 

 

 

 

 

2.mysqld运行之后,创建的文件的权限:——备注:mysqld运行之后,生成的文件,目录用户和用户组都是mysql.

 

 

 

小结:

简单来说,--user选项,

1、是在哪个用户下执行mysqld程序,

2、 mysqld程序创建的文件,目录的用户权限是哪个用户.

能够运行的主要原因:文件及目录权限.

 

posted @ 2023-11-11 15:57  小白龙白龙马  阅读(89)  评论(0编辑  收藏  举报