最近在搞node,接触了mysql遇到点问题

下载exporess插件

cnpm install express --save

创建后端目录

  • |-- 后端
    *|-- config

下载mysql插件

cnpm install mysql --save

下载multer插件

有利于图片上传的插件

cnpm install multer --save

下载ejs插件

用于解析html


cnpm install ejs --save

创建index.js文件

后端数据库分析及创建

分析数据表
创建mysql数据
添加sql语句

有时候mysql连不上?
卸载重新搞吧!

MAC系统:10.15.6 数据库:mysql 8.0

MySQL完全删除:

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
  • 检查/usr/local/Cellar目录是否有mysql文件,有的话删除。
  • 检查/usr/local/var 里的mysql文件,有的话删除。
  • 检查/tmp 里的mysql.sock、mysql.sock.lock、 my.cnf文件,有的话删除。
  • err文件以及pid文件都是在/usr/local/var/mysql中,有的话删除。
  • brew安装的安装包存储是在/usr/local/Library/Cache/Homebrew,有的话删除。
  • 执行brew cleanup。

以上步骤路径可能不一致,需要仔细寻找

安装就很简单了,MAC安装了brew命令就可以直接

brew install mysql@8.0

安装mysql

brew install mysql

安装完成提示如下:

==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.21.sierra.bottle.
######################################################################## 100.0%
==> Pouring mysql-5.7.21.sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.7.21/bin/mysqld --initialize-insecure --user=xuemi
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
 /usr/local/Cellar/mysql/5.7.21: 323 files, 233.9MB

注意:

  • 如果提示如下:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

说明mysql服务没有启动需要执行:

mysql_secure_installation

出现以下提示:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.
//验证密码插件可以用来测试密码和提高安全性。它检查密码的强度,并允许用户只设置那些足够安全的密码。你愿意安装验证密码插件吗?
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
//在下边的问题中输入y或者Y,输入其他的都表示为否
Press y|Y for Yes, any other key for No:y

// 密码验证策略有三个级别:
// 低长度> = 8
// 中长度>= 8,数字,混合情况,和特殊字符。
// 强长度>= 8,数字,混合情况,特殊字符和字典文件。

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

// 0,1,2分别代表3个不同的级别,看自己的生产环境需要的密码需求

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:0

// 请在这里设置root的密码。
// 新密码:
// 重新输入新密码:
// 估计密码强度:50。

// 您希望继续提供密码吗?(请按y| y为Yes,任何其他关键字):


Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :y

// 默认情况下,MySQL安装有匿名用户,
// 允许任何人在不需要的情况下登录MySQL。
// 为它们创建的用户帐户。这仅仅是为了。
// 测试,并使安装更加顺利。
// 在开始生产之前,你应该把它们去掉。
// 环境。
// 删除匿名用户?(请按y| y为Yes,任何其他关键字):

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :y

// 成功。
// 通常,根应该只允许连接。
// “localhost”。这确保了某人无法猜测。
// 来自网络的根密码。
// 不允许远程root登录吗?(请按y| y为Yes,任何其他关键字):
// 这里表示是否允许远程登录root用户,我这里是测试环境,选择键入Y

Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :y

成功。

// 默认情况下,MySQL附带一个名为“test”的数据库。
// 任何人都可以访问。这也只用于测试,
// 在开始生产之前应该将其移除。
// 环境。
// 这里提示是否删除mysql的test数据库


删除测试数据库并访问它?(请按y| y为Yes,任何其他关键字):

Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) :y


// ——删除测试数据库……
// 成功。
// -删除测试数据库上的特权…
// 成功。
// 重新加载特权表将确保所有更改。
// 到目前为止,将立即生效。
// 现在重新加载权限表吗?(请按y| y为Yes,任何其他关键字):
- Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :y


Success.
//出现此消息,说明mysql设置成功,请牢记输入的mysql密码
All done!

登录mysql进行测试

mysql -u root -p

🎉成功,撒花🎉

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值