阿里云聊天室用 MySQL 基础配置及命令及表定义

MySQL basics

i-hp3hnf62749w4chl22p1*************************

五、启动、停止、重启、进入mysql服务的命令
启动:
sudo service mysql start
停止:
sudo service mysql stop
重启:
sudo service mysql restart
进入:
mysql -uroot -p

// 后台运行进程
nohup COMMAND &

//检查以下mysql的端口状态
netstat -anp|grep mysql
如果显示127.0.0.1:3306 则说明需要修改,若为: : :3306,则不用

因为我显示的状态是127.0.0.1:3306是这个值,所以得去修改。

网上查到的大多数修改配置文件路径均说是在**/etc/mysql/my.cnf**,但这是对旧版本而已,由于我装的是最新版,所以打开这个文件之后发现里面并没有bind_address这个给值。后来查了一下才发现,新版的是在**/etc/mysql/mysql.conf.d/mysqld.cnf**。既然发现问题所在,那么改过来就很方便了。找到下面这部分,然后注释掉即可。
————————————————
版权声明:本段为CSDN博主「jiangxiaoju」的原创文章
原文链接:https://blog.csdn.net/qq_43058685/article/details/104267351


mysql -u root -p password
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> select user,host from user;
+------------------+----------------+
| user             | host           |
+------------------+----------------+
| root             | localhost              |
| debian-sys-maint | localhost      |
| mysql.session    | localhost      |
| mysql.sys        | localhost      |
+------------------+----------------+
————————————————
grant all privileges  on *.* to new_user@'%' identified by "password";

grant all privileges  on *.* to smbc@‘%’ identified by ‘1qaz@WSX’;

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


CREATE TABLE `user` (
  `user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `password` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT '111111',
  `sex` smallint(6) NOT NULL DEFAULT '0',
  `icon` longtext COLLATE utf8mb4_unicode_ci,
  `remark` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT '无',
  `crt_date` datetime NOT NULL,
  `upd_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

CREATE TABLE `message` (
  `message_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `send_user_id` int(10) unsigned NOT NULL,
  `text` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
  `image` longtext COLLATE utf8mb4_unicode_ci,
  `type_id` smallint(6) NOT NULL DEFAULT '0',
  `mark1` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`message_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

CREATE TABLE `push_message` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `message_id` bigint(20) unsigned NOT NULL,
  `receiver_id` int(10) unsigned NOT NULL,
  `is_sent` tinyint(4) NOT NULL DEFAULT '0',
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

CREATE TABLE `session` (
        `session_key` char(64) NOT NULL,
        `session_data` blob,
        `session_expiry` int(11) unsigned NOT NULL,
        PRIMARY KEY (`session_key`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4  COLLATE=utf8mb4_unicode_ci;

MySQL 5.5 之前, UTF8 编码只支持1-3个字节,从MYSQL5.5开始,可支持4个字节UTF编码utf8mb4,一个字符最多能有4字节,utf8mb4兼容utf8,所以能支持更多的字符集;关于emoji表情的话mysql的utf8是不支持,需要修改设置为utf8mb4,才能支持。

 

 

你可能感兴趣的:(记录)