栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

阿里云部署 2.mysql

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

阿里云部署 2.mysql

更多文章欢迎大家关注微信公众号 前端阅读室 mysql 下载

直接使用yum快速搭建

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
启停mysql服务

启动

[root@iZ8vbfhrv1vsbp44n9fdtoZ ~]# systemctl start  mysqld.service

使用ps -ef | grep mysql查看,发现mysql服务已经启动了。

[root@iZ8vbfhrv1vsbp44n9fdtoZ ~]# ps -ef | grep mysql
mysql    21709     1  6 10:58 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root     21738 21649  0 10:58 pts/0    00:00:00 grep --color=auto mysql

停止

[root@iZ8vbfhrv1vsbp44n9fdtoZ ~]# systemctl stop  mysqld.service

mysql服务停止了

[root@iZ8vbfhrv1vsbp44n9fdtoZ ~]# ps -ef | grep mysql
root     21747 21649  0 10:58 pts/0    00:00:00 grep --color=auto mysql
[root@iZ8vbfhrv1vsbp44n9fdtoZ ~]# systemctl start  mysqld.service
重设root密码,设置远程登录权限

先设置免密登录

vim /etc/my.cnf

在mysqld下面添加
skip-grant-tables
保存后重启mysql,这时就可以跳过密码来登录mysql了

systemctl stop  mysqld.service
systemctl start  mysqld.service
mysql

先刷新

mysql>flush privileges;

创建用户
mysql>create user ‘root’@‘localhost’ identified by ‘你的密码’;
允许root用户远程登录
mysql>grant all privileges on . to ‘root’@’%’ identified by ‘你的密码’;
刷新
mysql>flush privileges;
去掉my.cnf里的免密设置,使用密码登录

mysql -u root -p '你的密码'

你还需要按照之前的方法添加安全组规则,打开服务器防火墙上的3306端口。
配置完毕后你就可以在本地远程连接服务器上的mysql了。

测试

我用的是npm上的Sequelize包,它是基于promise的,支持es6语法。除了mysql,它还可以用于连接Postgres、MariaDB、SQLite和Microsoft SQL Server。(https://www.npmjs.com/package/sequelize)

结合开发文档,我们就可以进行实际开发了。

const Sequelize = require('sequelize');
const config = require('../config');

const logger = require('log4js').getLogger('app');

class MysqlClient {
  constructor() {
    if (!MysqlClient.instance) {
      this.client = new Sequelize(config.mysql.database, config.mysql.username, config.mysql.password, {
 host: config.mysql.host,
 port: config.mysql.port,
 dialect: 'mysql',
 pool: {
   max: 5,
   min: 0,
   idle: 10000,
 },
 timezone: '+08:00',
      });

      const client = this.client;
      MysqlClient.instance = client;

      client
      .authenticate()
      .then(() => {
 logger.info('Connection has been established successfully.');
      })
      .catch(err => {
 logger.info('Unable to connect to the database:', err);
      });
    }
  }
}

module.exports = new MysqlClient().client;
转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号