I asked this question 1 hour ago:
How can I transfer my data from one database(000webhosting.com) to another(shatellhost.com)? note: I use 000webhosting.com free hosting service and I can't create full backup. my data is phpfox social networking.
No one answered so I did this:
I transfered (download) whole data in public-html in 000webhosting.com to my computer and then uploded whole that to public-html of my new host in shotellhost.com, then when i try to open my site: www.ibiology.ir this appears:
Cannot connect to the database:
Can't connect to MySQL server on 'mysql5.000webhost.com' (4)
How can i change MySQL address to new MySQL?
Do a mysqldump and then import the SQL into your new database.
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
This error appears to be due to the configuration file of your PHP code, the connection information did not changed properly when you change the host.
First thing to do is make sure that you have change your database. Because of the security reason, most hosting service does not allow connecting to there mysql server from another location. There for, you connect to the mysql5.000webhost.com from another server.
Second, review the code to find out which file containing the database connection information, which usually includes: database hostname, database username, database password, database name. If you use an PHP framework, check the documentation.
In general, this is what I usually do when moving a site to another host:
Open the PHPMyAdmin in my old host control panel
Export the full data of the current database. I usually check DROP TABLE/DROP VIEW option.
Save the exported sql file to my local drive
Open the control panel of my new host
Finding the MySQL configuration option. You may find the MySQL host name here, usualy is localhost (yes, 000webhost is a special case when not use this default host name).
Create the database and the user if necessary.
Write the database hostname, database username, database password, database name information properly into your php configuration file of your source code.
Open the PHPMyAdmin in the control panel of the new host, go to my database (just created) and import the previous sql file.
If everything works well, your code may work.
Related
I have managed to create a droplet on Digital-Ocean and managed to clone my Node JS app onto it. Locally , the app connects to MySQL database and I wanted to the same on the live version. Ignorantly, I attempted to create a Managed database cluster which I did and added 1 user account and created 1 database. Right now I do not know how I can import the exported database.sql file into the database since I am only used to phpMyAdmin.
How can I get this to work and connect to my NodeJS app?
You were using phpmyadmin as an interactive Mysql client program. It's easy to use but hard to set up because it's a web app.
Try another MySql client program. The command-line client, memorably named mysql, is a good choice.
Get a shell on your droplet, then say
sudo apt install -y mysql-client
mysql -u username -p -h databasehostname -D database
mysql> source database.sql
mysql> quit
You'll be prompted for your database password.
That should import your database.
The mysql command line program is very useful and worth some of your time to learn to use.
First, make sure your database cluster is not open to the outside world by adding a DB firewall using DigitalOcean databases. You can allow connections from your own droplet's private IP address, and your own public address (or VPN or however way you're set up). Once you've done that, you should be able to import your SQL file locally (or from the DO Droplet, as long as you have the mysql client installed):
mysql -h [host-provided-do] -P [port-provided-do] -u [username-provided-do] -p [db-name-provided-do] < my-file.sql
The most important thing is to make sure your managed database is not open to the outside world, and that you make sure it only allows incoming connections from known IP addresses.
In your NodeJS app, you can set the driver to connect to the private subnet that DO provides.
Non-coder here, please advise as newbie. I have a MySQL DB on my ISP's server that provides data for a web site. I want to set up a db on my localhost that I can use for local development. The DBs don't need to be linked, nor do they need to remain synchronized. I just need to start with a current copy of the ISP version.
I have used PHPMyAdmin on ISP to download what I think is a dump file. the file, [mydbname].sql shows the schema and all the data. I just can't figure out how to import it in MySQL Workbench on my local PC.
Using the MySQL Workbench Data Import tab, if I execute "Import from Dump Project Folder" where the .sql file is located, I get "There were no dump files in the selected folder."
If I select "Import from Self-Contained File" and select my ***.sql file, I get "ERROR 1142 (42000) at line 31: CREATE command denied to user 'root'#'localhost' for table 'account' Operation failed with exitcode 1"
I've attempted to give 'root'#'localhost' all privileges.
I'm guessing there's an issue with privileges. If there's another way to do this, I'd be thrilled to know it. Many thanks!
If what you have is a sql dump file then try this on the CLI:
mysql -h hostname -u user --password=password databasename < filename
Assuming of course that has the right privileges.
Non-coder here, please advise as newbie.
In that case, download heidisql : https://www.heidisql.com/
It also makes copying tables and database from server to server very easy.
Apart from that: there is most likely something wrong with your privileges. But you might have made that worse by trying to give privileges to root. The root user can already do everything. So maybe also have a look at this post : How can I restore the MySQL root user’s full privileges?
I'm struggling to use the Workbench software for a database saved on my desktop. I do normally work with SQL server online but in our case the client sent us directly the local file.
Do you know how if it is possible?
Thanks
NC
create a new database
create database database_name
import the '.sql' file provided to you into it
mysql -u username -p database_name < path/to/database_file.sql
the database will be visible then.
you can use the workbench gui instead. ensure you have created a new database first then import.
I have cPanel & WHM installed on my server.
Is it safe to backup this directory (if I only care about backing up the MySQL databases):
"/var/lib/mysql/"
I don't care about the other MySQL databases that cPanel provide by default. I only care about the MySQL databases that other cPanel users have created and currently own.
I know I could just back it up with other ways, but let's say due to a hard disk drive failure, I cannot access cPanel and WHM.
The only access to the server I have is via SSH (and SFTP).
Okay, so would it be my best interest to just download everything in "/var/lib/mysql/"?
If not, what other files would I need to back up? Let me guess, just the "/home/" directory?
I hope my description of my issue was made clear and was descriptive.
Basically, I need to transfer the MySQL databases from one HDD to another, but the HDD with the MySQL databases has lots of errors, is corrupted (I cannot access cPanel/WHM) and my server provider tells me my HDD has failed.
In advance, I would like to thank you very much for your help.
Even if you did not help, thank you very much for taking your time reading this. It is much appreciated.
You mentioned that you can access the server via SSH but have no access to WHM or cPanel. I guess you have no access to phpMyAdmin(?). I am also guessing that the second HDD is on another server.
Instead of backing up a directory, I would suggest you connect via SSH to your server, then make remote backups with mysqldump, download them locally with SFTP and then import the database backups to the other HDD/server.
Connect to your server with SSH
ssh root#xxx.xxx.xxx.xx1
Where xxx.xxx.xxx.xx1 is the IP address of your first server. Give your password when prompted.
Use mysqldump to make a backup of your database(s) to the server.
mysqldump -uroot -p mydatabase1 > mydatabase1.sql
mysqldump -uroot -p mydatabase2 > mydatabase2.sql
...
Type your MySQL password when prompted and then the sql files (backups of your databases) will be created. I would suggest you don't make the backups on a publicly available directory of your server.
If you are on a Unix system you can type "ll" or "ls" to see that the .sql files have been created. Make a note of the directory in your server where the backups are located.
Terminate the SSH session:
exit
Then use your favourite SFTP program to connect to your server or use terminal like this:
sftp root#mywebsite.com
Type your password when prompted.
Navigate to the directory where the backups are located and download them by using the "GET" command:
get mydatabase1.sql
Your mydatabase1.sql backup file will be downloaded to your local machine.
Don't forget to close the session:
exit
Now SFTP to your other HDD to upload the database backups:
sftp root#xxx.xxx.xxx.xx2
where xxx.xxx.xxx.xx2 is the IP address of your other machine. Give password when prompted.
Don't forget to close the SFTP session:
exit
Now that you have uploaded the databases, you can connect again with SSH to the other HDD/server just like before:
ssh root#xxx.xxx.xxx.xx2
Once connected, create the new database:
mysql -uroot -e "create database mydatabase1"
Import the backup to the database:
mysql -uroot -p mydatabase1 < mydatabase1.sql
Now the database backup should be imported in the new server/hdd. I hope this helps.
I have a local MYSQL DB running under WAMP that I need to move up to my production DB server. New to MySQL and need to know the best way to get this DB moved up.
you can run this on your current server:
mysqldump -u user -p database_name > dump.txt
and then do this on your new server:
mysql -u user -p database_name < dump.txt
Replace "user" with your username and "database_name" with a name of your database. You'll be prompted for a password in both cases
Note that second command will replace old tables in your new database
Open up your database in phpMyAdmin and then select Export from the menu. Scroll down and select the Save as file checkbox and then press Go.
Now open up the database in phpMyAdmin on the production server (Note: you will need to create the database first) and then select Import from the menu. Browser to the file you saved and press Go.
If everything goes well you should now have a mirror image of your database on the production server! :)
Do you have phpmyadmin? (If you're not sure, type "http://localhost/phpmyadmin"). If you do, go to "Export on your local computer, and then upload that file on the "Import" section of the remote server. This is the absolute easiest way, and 90% of hosts have phpmyadmin installed.
If you don't, use the command line method suggested by ZeppLock.