是否可以在 Windows (XAMPP) 和 Linux (LAMP) 上使用相同的 MySQL 数据库?
我有 Windows 7 和 Ubuntu 10 的双启动模式。
在 Windows 7 上我安装了 XAMPP,在 Linux 上我安装了 LAMP。
是否可以强制安装在不同操作系统上的MySQL数据库服务器(即使它们具有相同的版本,但它们是不同的)使用相同的物理文件?
所以在双启动模式下,与我运行另一个操作系统的事实无关,我将能够使用相同的物理数据。有时我想切换操作系统,但如果能够使用相同的数据库那就太好了。
I have dual boot mode with Windows 7 and Ubuntu 10.
On Windows 7 I have XAMPP installed, on Linux I have LAMP installed.
Is it possible to force the MySQL DB servers installed onto different operating systems (even though they would be of identical versions, they are different) to use the same physical files?
So in dual boot mode, independently from the fact that I ran another operating system, I would be able to use the same physical data. Sometimes I'd like to switch OS but it would be great to be able to use the same databases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在您的
my.ini
(在 Windows 中,它位于C:\Program Files\MySQL\MySQL Server 5.1
等位置。它是 MySQL 的主要配置文件)文件中,您应该有这一行:datadir="C:/ProgramData/MySQL/MySQL Server 5.1/Data/"
例如,在 Windows 和 Linux Ubuntu 中将其更改为指向一个物理文件夹(在带有Windows 可以识别的文件系统)。它会起作用的。文件格式相同。
无论您是从 Ubuntu 还是 Windows 7 启动,都没关系,2 个不同版本的 MySQL 将在同一位置查找数据。一旦在 Windows 环境中修改了数据,您从 Ubuntu 启动,数据就在那里并被修改。
in your
my.ini
(in Windows it's located somewhere likeC:\Program Files\MySQL\MySQL Server 5.1
. It's the main configuration file for MySQL) file, you should have this line:datadir="C:/ProgramData/MySQL/MySQL Server 5.1/Data/"
for examplechange it in both Windows and Linux Ubuntu to point to one single physical folder (on a partition with a file system which Windows could recognize). It will work. File formats are identical.
Whether you boot from Ubuntu, or Windows 7, it won't matter, 2 different builds of MySQL will be looking for data in the same place. Once data is modified in Windows environment, you boot up from Ubuntu and the data is there, modified.
虽然并不理想,但只要满足以下条件就应该没问题:
您在两个操作系统上使用相同版本的 MySQL。
在复制数据文件之前关闭 mysqld。 (如果您要在分区之间复制数据文件,而不是将它们保存在共享的 fat32 分区上)。
本质上,只要MySQL运行在相同“字节顺序”的架构上,那么文件格式就应该是可转移的。
建议您关闭 ICQ 等,然后使用空闲内存在 VirtualBox 虚拟环境中运行 Ubuntu计算机位于 Windows 7 之上 - 因此确保您可以轻松访问您的开发环境,而无需重新启动等。
这实际上是一个非常好的设置,因为这意味着您可以使用 Windows 开发环境(如果您愿意)并且只需托管网站 Web Ubuntu 虚拟机上 Samba 装载上的站点数据。
Whilst not ideal, this should be fine as long as:
You're using identical versions of MySQL on both operating systems.
You shutdown mysqld before you copy the data files across. (If you're going to be copying the data files between partitions rather than keeping them on a shared fat32 partition).
In essence, as long as MySQL is running on an architecture of the same "endianness", then the file formats should be transferable.
As a suggestion, you could just close ICQ, etc. and use the free memory to run Ubuntu within a VirtualBox virtual machine on top of Windows 7 - hence ensuring you can trivially access your development environment without having to restart, etc.
This is actually quite a nice set up as it means you can use a Windows development environment if you want and simply host the site web site data on a Samba mount on the Ubuntu virtual machine.
只要数据在两个操作系统上都是可共享/可读取/可写的,并且两个文件格式在两个操作系统上都相同,那么它应该是可行的。
我可以想象的第一个问题是Windows中不区分大小写。< br>
因此,如果您始终使用 CamelCase,请将您的数据库/表转换为驼峰命名法(或驼峰命名法)。
更多信息请阅读 - http://dev.mysql.com /doc/refman/5.0/en/limits-windows.html
As long as the data is sharedable/reable/writeable on both OS, and both file format are identical on both OS, it should be doable
The first problem I can imagine is the case insensitivity in windows.
so, convert your database/table ti camel_case (or camelcase) if you are always using CamelCase.
More information to read up - http://dev.mysql.com/doc/refman/5.0/en/limits-windows.html
当然可以。
但我不认为,你的双启动系统是可能的。
假设您的MySQL服务器安装在Win7机器下。你可以从Win7环境完美访问它,甚至从Linux环境也可以完美访问它(如果你的MySQL服务器设置中没有拒绝访问)。
安装 MySQL 的系统必须正在运行!然后,如果允许,您可以从多个系统访问它;-)
Of course you can.
But I dont think, it is possible for your dual boot system.
Lets assume, your MySQL server is installed under Win7 machine. You can perfectly access it from Win7 enviroment, and even from Linux enviroment (if you do not deny access in your MySQL server settings).
The system, which is your MySQL installed under, has to be running! Then you can access it from multiple systems if allowed ;-)
我琢磨了很多时间,发现运行Linux内核是一个可以解决的方法和可行的解决方案。
Vagrant
它是一个用于在单个工作流程中构建和管理虚拟机环境的工具。我认为你使用 vagrant 的主要原因是它不太重并且不会占用你的太多计算机资源。我相信您阅读了 Vagrant 文档,它将允许您启动基于 Linux 的计算机你的物理机。
假设主机分配了 IP
192.168.1.2
,虚拟机的 IP 地址为192.168.1.10
,并确保主机和访客计算机可以看到彼此。请仔细阅读网络部分以自定义网络配置。验证主机和来宾计算机之间的连接
安装 MySQL 服务器
MySQL 是一个数据库管理系统。基本上,它将组织并提供对我们网站可以存储信息的数据库的访问。
在上述步骤已设置的机器中打开终端。运行以下命令:
sudo apt-get install mysql-server-5.6
注意:这取决于安装的 Linux 发行版的版本,上面的命令可以根据您的情况进行调整需要。对于安装,我使用了 Ubuntu 14.04 的核心,请参阅链接。
在安装过程中,您的服务器将要求您选择并确认 MySQL
root
用户的密码。这是 MySQL 中的一个管理帐户,具有更高的权限。验证安装
从来宾计算机(即虚拟机)的终端中,运行以下命令:
mysql -u root -p
将询问 MySQL 密码,然后提供您在 MySQL Server 安装期间设置的密码。如果您向 MySQL 服务器提供正确的信息,则屏幕截图如下。
远程访问 MySQL 服务器
因为我们需要一个集中式数据库服务器,其他计算机可以在其中访问并连接到感兴趣的数据库。再次打开终端并运行以下 MySQL 命令:
使用授予选项将 *.* 上的所有权限授予由密码“*4ACFE3202A5FF5CF467898FC58AAB1D615029441”标识的“root”@“192.168.1.2”;
使用授予选项将“@”上的代理授予“root”@“192.168.1.2”;
同花顺特权;
其中
192.168.1.2
是主机的 IP 地址,以及从中的
user
表获取的password
的散列字符串mysql 数据库。好的。如果目前没有问题,您可以休息一下并享用饮品。
验证远程访问
从主机上的终端启动以下命令:
mysql -h192.168.1.2 -uroot -p
,该命令要求您输入密码。如果根凭据正确,您将看到类似上面的屏幕截图。需要注意的一件事是在
mysql
命令后面添加-h192.168.1.2
,因为我们不在安装MySQL服务器的机器上。总而言之,我们已经设置了一个用于主机和来宾机器的 MySQL 服务器。实际上,如果我有另一台分配了
192.168.1.3
的机器也可以连接到数据库服务器并在服务器和客户端之间交换数据。I goggled a lot of time and found that running a Linux kernel is a solvable way and feasible solution.
Vagrant
It is a tool for building and managing virtual machine environments in a single workflow. The main reason why I argue you using
vagrant
is that it is not too heavy and does not swallow much of your computer resources. I believe you get through Vagrant documentation that will allow you to launch a Linux based machine on your physical machine.Let's assume that the host machine is assigned IP
192.168.1.2
and the virtual machine has the IP address as192.168.1.10
, and make sure that the host and guest machine could see each other. Please read thoroughly Networking section to customise the network configuration.Verifying connection between host and guest machine
Install MySQL Server
MySQL is a database management system. Basically, it will organise and provide access to databases where our site can store information.
Open a terminal in the machine has been set up from the above step. Run the following command:
sudo apt-get install mysql-server-5.6
Notes: It's up to the version of Linux distribution installed, the above command would be adjustable to suit your need. For install, I used the core of Ubuntu 14.04, see the link.
During the installation, your server will ask you to select and confirm a password for the MySQL
root
user. This is an administrative account in MySQL that has increased privileges.Verifying the installation
From a terminal in the guest machine (i.e. the virtual machine), run the following command:
mysql -u root -p
will ask the MySQL password, then provide the one you have set up during MySQL Server installation. The following is the screenshot if you feed correct information to MySQL server.
Turn MySQL Server remotely accessible
Because we need a centralised database server where other computers could access and connect to the database of interest. Again, open a terminal and run the following MySQL commands:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.2' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' WITH GRANT OPTION;
GRANT PROXY ON ''@'' TO 'root'@'192.168.1.2' WITH GRANT OPTION;
FLUSH PRIVILEGES;
which
192.168.1.2
is the IP address of the host machine and hashed string ofpassword
gets fromuser
table inmysql
database.Okay. You might take a rest and enjoy your drink if there is no issue so far.
Verifying the remote access
From a terminal on the host machine, fire up the following command:
mysql -h192.168.1.2 -uroot -p
which is asking you to enter the password. If the root credential is correct, you would see a screenshot like the above one. One thing needs to be paid attention is to add
-h192.168.1.2
followingmysql
command because we are not in the machine where MySQL server is installed.All in all, we have set up a MySQL server used for both host and guest machine. In reality, if I have another machine assigned
192.168.1.3
can also connect to the database server and exchange data between server and client.