网易内推联系我哦

网易无偿内推,点击下方【首页】置顶帖查看说明

0%

安装步骤

查看服务器版本

系统版本:

$ lsb_release -cr
Release:        9.12
Codename:       stretch

内核版本:

$ uname -r
4.9.0-12-amd64

下载 MySQL

根据服务器版本,下载 MySQL 安装包。

下载地址:https://downloads.mysql.com/archives/community/

安装 MySQL

以下载的 mysql-server_5.7.18-1debian9_amd64.deb-bundle.tar 为例进行说明。

解压 tar:

$ gzip mysql-server_5.7.18-1debian9_amd64.deb-bundle.tar

解压 tar.gz:

$ tar -zxvf mysql-server_5.7.18-1debian9_amd64.deb-bundle.tar.gz

安装 deb 包:

$ dpkg -i *.deb

初始化 MySQL

$ /usr/sbin/mysqld --defaults-file=/home/ddb/mysql/my3306.cnf --user=ddb --initialize

启动 MySQL

$ mysqld_safe --defaults-file=/home/ddb/mysql/my3306.cnf &

查看 root 密码

查看 MySQL 数据目录下的 mysqld.log 日志文件,如下图所示红框的地方即为 root 的初始密码。

image-20210604114352669

访问 root

$ mysql  --defaults-file=/home/ddb/mysql/my4336.cnf -uroot -p
Enter password:

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

此时,必须修改 root 密码。

修改 root 密码

SET PASSWORD = PASSWORD('newpassword');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;

问题处理

安装 deb 异常

安装 deb 包时出现如下异常:

dpkg: dependency problems prevent configuration of mysql-community-server:
 mysql-community-server depends on libaio1 (>= 0.3.93); however:
  Package libaio1 is not installed.
 mysql-community-server depends on libmecab2; however:
  Package libmecab2 is not installed.
 mysql-community-server depends on libnuma1 (>= 2.0.11); however:
  Package libnuma1 is not installed.

解决方式:

$ apt-get install libaio1 libmecab2 libnuma1

初始化异常

2021-06-04T11:13:04.485999+08:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-06-04T11:13:04.487043+08:00 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2021-06-04T11:13:04.487070+08:00 0 [ERROR] Aborting

这是由于初始化数据目录不为空,清空数据目录下的所有文件即可。

在项目中,有部分数据是以 JsonObject 和 JsonArray 的形式直接存储在 MySQL 中的。

如果想对 这部分数据进行查询 等操作,非常不便。

经查询,MySQL 5.7.8 新增了对 Json 数据的相关支持,MySQL 8.0.4 新增了 Json 表函数的功能。

通过使用 内置的 函数,可以非常方便的对以 JsonObject 和 JsonArray 的形式直接存储在 MySQL 中的字段,进行查找、排序等操作。

本文总结了 MySQL 对 Json 操作的相关用法。

阅读全文 »

问题

tomcat 运行时,报如下异常:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Jueee/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Jueee/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.13.3/log4j-slf4j-impl-2.13.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. 
SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
26-May-2021 18:44:40.531 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
26-May-2021 18:44:40.531 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/adminWeb] startup failed due to previous errors
26-May-2021 18:44:40.545 警告 [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [adminWeb] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.Object.wait(Object.java:502)
 java.util.TimerThread.mainLoop(Timer.java:526)
 java.util.TimerThread.run(Timer.java:505)
阅读全文 »

使用 os.system ()

Python 示例:

import os
val = os.system('ls -al')
print val

返回的状态码

正常输出的情况下,sh 返回的状态码是 0

$ python test1.py
total 12
drwxr-xr-x 2 jue root 4096 May 25 11:18 .
drwx------ 4 jue root 4096 May 25 11:18 ..
-rw-r--r-- 1 jue root   46 May 25 11:18 test1.py
0

没有找到时,sh 返回的状态码是 1,而适用 Python 调用,返回的是:256

import os
val = os.system('ls -al|grep jue')
print val

调用 Python

$ python test1.py
256

使用 os.popen ()

使用 commands 模块

有三个方法可以使用:

  1. commands.getstatusoutput (cmd),其以字符串的形式返回的是输出结果和状态码,即(status,output)。
  2. commands.getoutput (cmd),返回 cmd 的输出结果。
  3. commands.getstatus (file),返回 ls -l file 的执行结果字符串,调用了 getoutput,不建议使用此方法

使用 subprocess 模块

subprocess 模块允许创建很多子进程,创建的时候能指定子进程和子进程的输入、输出、错误输出管道,执行后能获取输出结果和执行状态。

  1. subprocess.run ():python3.5 中新增的函数, 执行指定的命令, 等待命令执行完成后返回一个包含执行结果的 CompletedProcess 类的实例。
  2. subprocess.call ():执行指定的命令, 返回命令执行状态, 功能类似 os.system(cmd)。
  3. subprocess.check_call ():python2.5 中新增的函数,执行指定的命令,如果执行成功则返回状态码, 否则抛出异常。