const pool = mysql.createPool({
connectionLimit: 100,
host: process.env.NEXT_PUBLIC_MYSQL_HOST,
user: process.env.NEXT_PUBLIC_MYSQL_USER,
password: process.env.NEXT_PUBLIC_MYSQL_PASSWORD,
database: process.env.NEXT_PUBLIC_MYSQL_DATABASE,
});
字符串
我希望你显示示例代码为我使用.env连接到mysql的nextjs
1条答案
按热度按时间polkgigr1#
NEXT_PUBLIC是浏览器中可访问的环境变量。读取:https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
我认为你不想显示这些值。
在你的.env或.env.local中,你可以这样写环境变量:
MYSQL_HOST=”127.0.0.1“//或远程中的“192.168.XX.XX”
然后,你可以像这样调用环境变量:
字符串
它对我和mariadb很有效。
你可以看到Vipin博士的教程:https://geniusvipin.medium.com/build-crud-app-with-next-js-server-actions-and-mysql-1e4427dc8800