从外部流浪者连接到MySQL

编程入门 行业动态 更新时间:2024-10-24 08:24:05
本文介绍了从外部流浪者连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用mycli连接到在无业游民的实例中运行的MySQL服务器.

I would like to connect with mycli to the MySQL server running inside a vagrant instance.

我的基本Vagrantfile看起来像下面的代码片段:

My basic Vagrantfile looks like the following code snippet:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" config.vm.box = "debian/wheezy64" config.vm.provision :shell, path: "misc/bootstrap.sh" config.vmwork "forwarded_port", guest: 80, host: 8082 config.vm.synced_folder ".", "/var/www/", owner: "vagrant", group: "www-data", mount_options: ["dmode=775,fmode=664"], create: true config.vm.provider "virtualbox" do |vb| vb.memory = 1536 vb.cpus = 1 end end

要安装必要的软件,我使用以下代码片段:

To install the neccessary software I am using the following code snippet:

echo "mysql-server mysql-server/root_password password $DBPASSWD" | debconf-set-selections echo "mysql-server mysql-server/root_password_again password $DBPASSWD" | debconf-set-selections echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections echo "phpmyadmin phpmyadmin/app-password-confirm password $DBPASSWD" | debconf-set-selections echo "phpmyadmin phpmyadmin/mysql/admin-pass password $DBPASSWD" | debconf-set-selections echo "phpmyadmin phpmyadmin/mysql/app-pass password $DBPASSWD" | debconf-set-selections echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect none" | debconf-set-selections sudo apt-get install -y apache2 libapache2-mod-php5 mysql-server php5-mysql php5 phpmyadmin php5-cli php5-curl vim sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/sites-available/phpmyadmin.conf sudo ln -s /etc/apache2/sites-available/phpmyadmin.conf /etc/apache2/sites-enabled/phpmyadmin.conf sudo a2enmod rewrite sudo a2enmod php5 sudo cp /var/www/misc/apache2.conf /etc/apache2/sites-available/default sudo service apache2 restart mysql -uroot -p$DBPASSWD -e "CREATE USER '$DBUSER'@'localhost' IDENTIFIED BY '$DBPASSWD';GRANT ALL ON *.* TO '$DBUSER'@'localhost';FLUSH PRIVILEGES;CREATE DATABASE $DBNAME;" mysql -u$DBUSER -p$DBPASSWD $DBNAME < /var/www/db.sql

我认为我的问题是我存储在数据库中的用户凭证.但是我不知道答案.

I think my problem is the user credentials which I am storing into the database. But I couln't figure out answer.

推荐答案

,您需要确保mysql在所有端口上侦听,而不仅仅是在本地侦听.

on top of what JRD said on the port forwarding, you need to make sure mysql listens on all port and not just locally

编辑/etc/mysql/myf文件,并确保

  • 您有bind-address = 0.0.0.0
  • 或者您在#bind-address ...
  • 行中添加注释
  • you have bind-address = 0.0.0.0
  • or you comment the line #bind-address ...

确保更改后重新启动mysql服务器

make sure to restart your mysql server after the change

$ sudo service mysql restart

然后您可以从主机进行连接-如果出现以下错误

Then you can connect from your host - In case you get the following error

$ mysql -h127.0.0.1 -P 33600 -uroot -p Enter password: ERROR 1130 (HY000): Host '172.16.42.2' is not allowed to connect to this MySQL server

然后回到客人那里做

vagrant@precise64:~$ mysql -h127.0.0.1 -uroot -p ... mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.42.2' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)

那么您应该没有问题可以从主机连接

Then you should have no issue to connect from the host machine

$ mysql -h127.0.0.1 -P 33600 -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 36 Server version: 5.5.44-0ubuntu0.12.04.1 (Ubuntu)

更多推荐

从外部流浪者连接到MySQL

本文发布于:2023-10-07 12:53:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流浪者   连接到   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!