将map集合转为json对象时遇到一个问题。map中 updateTime的value为日期格式如"2001-01-01",在使用 JSONObject.toJSON(map).toString() 的时候, 得到的结果 updateTime 的值为 时间戳 解决方法: 使用fastjson 的 JSON.toJSONStringWithDateFormat(Object,dateformat,SerializerFeature.WriteDateUseDateFormat) 方法即可将时间戳转换为自定义格式类型的值 from:https://blog.csdn.net/qq_39564789/article/details/105176845
View Details1.删除原有的mariadb 不然安装报错
|
1 |
rpm -qa|grep mariadb |
|
1 |
rpm -e --nodeps mariadb-libs |
2. 下载RPM安装包 在https://dev.mysql.com/downloads/mysql/选择为Red Hat Enterprise Linux 7 / Oracle Linux 7 ,把os的版本选择为all。 直接下载mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar,所有的rpm包都在里面,然后rpm命令安装。
|
1 2 3 4 5 6 7 8 9 10 11 |
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm |
至此,mysql5.7所有文件安装完毕,接下来就是开启服务测试了 3. 启动mysql服务 查看mysql服务是否启动
|
1 |
service mysqld status |
启动服务:
|
1 |
systemctl start mysqld |
4. 重置root密码 MySQL5.7会在安装后为root用户生成一个随机密码,而不是像以往版本的空密码。 可以安全模式修改root登录密码或者用随机密码登录修改密码。下面用随机密码方式 MySQL为root用户生成的随机密码通过mysqld.log文件可以查找到:
|
1 |
grep 'temporary password' /var/log/mysqld.log |
5. 修改root用户密码 (MySQL的密码策略比较复杂,过于简单的密码会被拒绝)
|
1 2 3 4 |
1 mysql -u root -p 2 mysql> Enter password: (输入刚才查询到的随机密码) 3 mysql> SET PASSWORD FOR 'root'@'localhost'= "qaz-123"; 4 mysql> exit |
6. 用root新密码登录
|
1 |
mysql -u root -pqaz-123 |
如果上面的方式不能修改可以使用下面安全模式修改root: 关闭服务,修改mysql配置文件:
|
1 2 |
1 systemctl stop mysqld.service 2 vi /etc/my.cnf |
mysqld下面添加skip-grant-tables 保存退出启动服务。
|
1 |
systemctl start mysqld.service |
|
1 2 3 4 5 6 7 |
mysql -u root #不用密码直接回车 use mysql update user set authentication_string=password('qaz-123') where user='root' and host='localhost'; flush privileges; exit; vi /etc/my.cnf #把 skip-grant-tables 一句删除保存退出重启mysql服务 systemctl restart mysqld.service |
再次登录即可
|
1 |
mysql -uroot -pqaz123 |
如果进行操作出现下面的提示:
|
1 |
You must reset your password using ALTER USER statement before executing this statement. |
就重新设置密码(mysql默认密码策略比较复杂,如果设置简单密码,需修改默认安全策略,可以参考另外一篇文章:MYSQL57密码策略修改)
|
1 |
set password = password('qaz-123'); |
7.开放3306端口
|
1 2 3 |
1 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qaz-123' WITH GRANT OPTION; 2 mysql>FLUSH PRIVILEGES; 3 mysql>exit; |
开启防火墙mysql 3306端口的外部访问:
|
1 2 |
1 firewall-cmd --zone=public --add-port=3306/tcp --permanent 2 firewall-cmd --reload |
from:https://www.cnblogs.com/mymelody/p/9253551.html
View Details服务器环境: centos7 x64 需要安装mysql5.7+ 一、卸载CentOS7系统自带mariadb
|
1 2 3 4 5 6 7 |
# 查看系统自带的Mariadb [root@CDH-141 ~]# rpm -qa|grep mariadb mariadb-libs-5.5.44-2.el7.centos.x86_64 # 卸载系统自带的Mariadb [root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64 # 删除etc目录下的my.cnf [root@CDH-141 ~]# rm /etc/my.cnf |
二、检查mysql是否存在
|
1 2 3 |
# 检查mysql是否存在 [root@CDH-141 ~]# rpm -qa | grep mysql [root@CDH-141 ~]# |
三、查看用户和组是否存在 1)检查mysql组合用户是否存在
|
1 2 3 |
# 检查mysql组和用户是否存在,如无则创建 [root@CDH-141 ~]# cat /etc/group | grep mysql [root@CDH-141 ~]# cat /etc/passwd | grep mysql |
# 查询全部用户(只是做记录,没必要执行)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@CDH-141 ~]# cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F ":" '{print $1 "|" $3 "1" $4}' | more root|010 sync|510 flume|9921989 hdfs|9911988 zookeeper|9891986 llama|9881985 httpfs|9871984 mapred|9861983 sqoop|9851982 yarn|9841981 kms|9831980 hive|9821979 oozie|9801977 hbase|9781975 impala|9761973 hue|9741971 wlaqzc2018|100111001 [root@CDH-141 mysql]# |
2)若不存在,则创建mysql组和用户
|
1 2 3 4 5 6 7 8 9 10 11 |
# 创建mysql用户组 [root@CDH-141 ~]# groupadd mysql # 创建一个用户名为mysql的用户,并加入mysql用户组 [root@CDH-141 ~]# useradd -g mysql mysql # 制定password 为111111 [root@CDH-141 ~]# passwd mysql Changing password for user mysql. New password: BAD PASSWORD: The password is a palindrome Retype new password: passwd: all authentication tokens updated successfully. |
四、下载mysql离线安装包tar文件 官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 版本选择,可以选择一下两种方式: 1)使用Red Hat Enterprise Linux Select Version:5.7.25 Select Operating System:Red Hat Enterprise Linux / Oracle Linux Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit) 列表中下载: Compressed TAR Archive:(mysql-5.7.25-el7-x86_64.tar.gz) 2)使用Linux – Generic Select Version:5.7.25 Select Operating System:Linux – Generic Select OS Version:Linux – Generic (glibc 2.12) (x86, 64-bit) 列表中下载: Compressed TAR Archive:(mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz)【本文中使用的是这个版本】 注意:上边两种方式找mysql离线安装包的方式都可以。 五、上传第四步下载的mysql TAR包
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 进入/usr/local/文件夹 [root@CDH-141 ~]# cd /usr/local/ # 上传mysql TAR包 [root@CDH-141 local]# rz # 解压mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz [root@CDH-141 local]# ls bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz share etc games lib libexec sbin src [root@CDH-141 local]# tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz mysql-5.7.25-lin ... mysql-5.7.25-linux-glibc2.12-x86_64/share/install_rewriter.sql mysql-5.7.25-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql mysql-5.7.25-linux-glibc2.12-x86_64/support-files/magic mysql-5.7.25-linux-glibc2.12-x86_64/support-files/mysql.server mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_BIN mysql-5.7.25-linux-glibc2.12-x86_64/docs/INFO_SRC [root@CDH-141 local]# ls bin full-path-to-mysql-VERSION-OS include lib64 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz share etc games lib libexec mysql-5.7.25-linux-glibc2.12-x86_64 sbin src # 进入/usr/local下,修改为mysql [root@CDH-141 local]# mv mysql-5.7.25-linux-glibc2.12-x86_64 mysql [root@CDH-141 local]# ls bin etc full-path-to-mysql-VERSION-OS games include lib lib64 libexec mysql mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz sbin share src |
六、更改所属的组和用户
|
1 2 3 4 5 6 7 |
# 更改所属的组和用户 [root@CDH-141 ~]# cd /usr/local/ [root@CDH-141 local]# chown -R mysql mysql/ [root@CDH-141 local]# chgrp -R mysql mysql/ [root@CDH-141 local]# cd mysql/ [root@CDH-141 mysql]# mkdir data [root@CDH-141 mysql]# chown -R mysql:mysql data |
七、在/etc下创建my.cnf文件
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 进入/usr/local/mysql文件夹下 [root@CDH-141 ~]# cd /usr/local/mysql # 创建my.cnf文件 [root@CDH-141 mysql]# touch my.cnf #或者cd ''>my.conf # 编辑my.cnf [root@CDH-141 mysql]# vi my.conf [mysql] socket=/var/lib/mysql/mysql.sock # set mysql client default chararter default-character-set=utf8 [mysqld] socket=/var/lib/mysql/mysql.sock # set mysql server port port = 3323 #默认是3306,这里发现3306已经被占用,因此防止这种情况发生,可以避免使用3306mysql默认端口 # set mysql install base dir basedir=/usr/local/mysql # set the data store dir datadir=/usr/local/mysql/data # set the number of allow max connnection max_connections=200 # set server charactre default encoding character-set-server=utf8 # the storage engine default-storage-engine=INNODB lower_case_table_names=1 max_allowed_packet=16M explicit_defaults_for_timestamp=true [mysql.server] user=mysql basedir=/usr/local/mysql [root@CDH-141 mysql]# |
八、进入mysql文件夹,并安装mysql
|
1 2 3 4 5 6 7 |
# 进入mysql [root@CDH-141 local]# cd /usr/local/mysql # 安装mysql [root@CDH-141 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 2019-03-08 18:11:07 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2019-03-08 18:11:24 [WARNING] The bootstrap log isn't empty: 2019-03-08 18:11:24 [WARNING] 2019-03-08T10:11:07.208602Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead |
设置文件及目录权限:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@CDH-141 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld [root@CDH-141 mysql]# chown 777 my.cnf [root@CDH-141 mysql]# ls bin COPYING data docs include lib man my.cnf README share support-files [root@CDH-141 mysql]# ls -l total 60 drwxr-xr-x 2 root root 4096 Mar 8 15:56 bin -rw-r--r-- 1 7161 31415 17987 Dec 21 18:39 COPYING drwxr-x--- 5 mysql mysql 4096 Mar 8 16:21 data drwxr-xr-x 2 root root 4096 Mar 8 15:56 docs drwxr-xr-x 3 root root 4096 Mar 8 15:56 include drwxr-xr-x 5 root root 4096 Mar 8 15:56 lib drwxr-xr-x 4 root root 4096 Mar 8 15:56 man -rw-r--r-- 1 777 root 516 Mar 8 16:19 my.cnf -rw-r--r-- 1 7161 31415 2478 Dec 21 18:39 README drwxr-xr-x 28 root root 4096 Mar 8 15:56 share drwxr-xr-x 2 root root 4096 Mar 8 15:56 support-files [root@CDH-141 mysql]# chmod +x /etc/init.d/mysqld [root@CDH-141 mysql]# [root@CDH-141 mysql]# mkdir data [root@CDH-141 mysql]# [root@CDH-141 mysql]# chown -R mysql:mysql data [root@CDH-141 mysql]# |
九、启动mysql
|
1 2 3 4 5 6 |
# 启动mysql [root@CDH-141 mysql]# /etc/init.d/mysqld restart MySQL server PID file could not be found![FAILED] Starting MySQL.Logging to '/usr/local/mysql/data/CDH-141.err'. ..The server quit without updating PID file (/usr/local/mysql/data/CDH-141.pid).[FAILED] [root@CDH-141 mysql]# |
出现错误,解决方案如下: […]
View DetailsObject转JSON字符串: String jsonStr = JSONObject.toJSONString(object); JSON字符串转JSONObject: JSONObject jsonObject = JSONObject.parseObject(jsonStr); JSON字符串转Object对象 T t = JSON.parseObject(jsonStr,T.class); —–注:JSON字符串是有格式要求的,必须为键值对形式,不是任意的字符串。—– ——————— 作者:KnifeBlade 来源:CSDN 原文:https://blog.csdn.net/qq_29468573/article/details/82190005
View Details在使用fastjson进行数据类型转换时发现,pojo类里面的属性首字母大写,在转成json之后,变成了小写。导致数据存储一直有问题。 转换之后结果为: 导致数据存储失败。(使用json传值进行持久化操作。) 解决方法: 在pojo类的属性get方法上加上你需要的key。 这样转换的json,对应的key就改变为你注解对应的属性名。 from:https://blog.csdn.net/cuuuc233/article/details/80983486
View DetailsJSONObject.toJSONString(Object object, SerializerFeature… features) Fastjson的SerializerFeature序列化属性 QuoteFieldNames———-输出key时是否使用双引号,默认为true WriteMapNullValue——–是否输出值为null的字段,默认为false WriteNullNumberAsZero—-数值字段如果为null,输出为0,而非null WriteNullListAsEmpty—–List字段如果为null,输出为[],而非null WriteNullStringAsEmpty—字符类型字段如果为null,输出为”“,而非null WriteNullBooleanAsFalse–Boolean字段如果为null,输出为false,而非nul
|
1 2 3 4 5 6 7 8 9 |
Map < String , Object > jsonMap = new HashMap< String , Object>(); jsonMap.put("a",1); jsonMap.put("b",""); jsonMap.put("c",null); jsonMap.put("d","dddddddddd"); String str = JSONObject.toJSONString(jsonMap,SerializerFeature.WriteMapNullValue); System.out.println(str); //输出结果:{"a":1,"b":"","c":null,"d":"dddddddddd"} |
from:http://www.voidcn.com/article/p-ebkhpvlq-bqh.html
View Details