Migrate MySql Database To New Server - mysql

I have done an export of my database to an .sql file.
When I try and upload this to my new server it comes up as access denied for user 'username' # '%'
The original database is called 'originalUsername_databaseName' where as it appears that the new server requires the prefix 'admin_'
I am convinced that it is the database name that is causing the error. Is there a way to change this ?

Make sure that your sql file does not contain CREATE DATABASE and USE statements.
If it does, remove them.
Create database manually and import tables to it.

Related

MySQL Workbench - How to clone a database on the same server with different name?

I am using MYSQL Workbench and I want to clone a database on the same server with different name. It should duplicate the all the tables structure and data into the new database.
I know the usual way is probably using data export to generate a sql script of the database and then run the script on the new database but I encounter some issues with it.
Anyway, is there any better way or easier way to do so?
You can use migration wizard from MySQL Workbench. Just choose the same local connection in both source and target selection, then change schema name on manual editing step. If nothing appears on manual editing step click next and the source and targets will appear. Click slowly on the source database name and edit to the correct name. Go thorough to the end and voilĂ  - you have two identical databases with different names. Note you must have created the target database already and granted permissions to it for the MySQL Workbench user.
I tried to do it in MySQL Workbench 8.0. However I kept receiving an error regarding column-statics. The main idea is to use mysqldump.exe, located in the installation directory of MySQL Workbench, to export the data. So, supposing a Windows oriented platform:
Open Powershell, navigate to mysqldump.exe directory. In my case the command is:
cd C:\Program Files\MySQL\MySQL Workbench 8.0 CE
Export database by executing mysqldump providing the right arguments:
./mysqldump.exe --host=[hostServerIP] --protocol=tcp --user=[nameOfUser] --password=[yourPassword] --dump-date=FALSE --disable-keys=FALSE --port=[portOfMysqlServer] --default-character-set=utf8 --skip-triggers --column-statistics=0 "[databaseName]"
Without changing directory, import the exported file (.sql) by using the following command in Powershell:
Get-Content "[pathToExportedDataFile]" | ./mysql.exe --user=[nameOfUser] --password=[yourPassword] --port=[portOfMysqlServer] --host=[hostServerIP] --database=[nameOfNewDatabase] --binary-mode=1
You can check in the documentation here for more information regarding the mysqldump options.
Please note the following:
Do not forget to replace the values in [] with your own values and remove the []. Do not remove the quotes("") where the are present.
Do not switch Powershell for cmd or something like git-bash, since the above will not work.
As far as step 3 is concerned, I created the new database from MySQL Workbench and then ran the powershell command.
List item First, create a new database using CREATE DATABASE statement.
Second, export all the database objects and data of the database from which you want to copy using mysqldump tool.
Third, import the SQL dump file into the new database.

mysql information_schema empty and not populating

Running WAMP localhost server With php 5.6.18 and MySQL 5.7.11 In project that im working on now i need to get some column data form information_schema.COLUMNS table, but information_schema DB is completely empty - 0 rows for every table in this DB For additional information - I have like 10 differnet DB on this MySQL, some are imported some are made from scratch in phpmyadmin.So im completely lost - tried to google but no luck.Maybe i miss something essential and trivial like some configuration of MySQL?
Execute this query:
mysql> SHOW GRANTS;
This will show you that either you are not logging in as the user you intend to use, or that this user lacks permissions on the tables in question.
In this case, the user may have no permissions at all. MySQL has a special permission called USAGE, which may seem slightly deceptively named if you aren't familiar with what it means. It means you can "use" the server -- that is, you can log in. But that is all it means. If you possess only the USAGE ON *.* privilege, this means you have permission to log in to the server, but no permissions on anything else.
The information_schema is integrated with the permissions system. You can't see information about database objects for which you don't have permissions. An empty information_schema.columns table suggests a permissions issue for the user you are using to connect to the server.
Sometimes this may be issue when you copy and paste the database's folders in mysql folder. Don't copy that way. The best way to export the databases using "export" command in "phpmyadmin" or use "mysqldump" command in mysql command line client to copy the data or export data from one to another.It will generate "yourdata.sql" file at the last , You can import that data using "export command in "phpmyadmin" . In your method is successful for "MyISAM" database driver in mysql. Modern mysql servers default database driver is "InnoDB" and it not success in when copy the database data folder on to another machine. If you have copy of previous copy of the databases from the old machine, try to export the "yourdata.sql" file using export method in "phpmyadmin" web interface.
I faced same problem when I transfer/shifted my mysql folder to other location.
And configured DB to point Mysql folder accordingly.
However, Information_schema was not getting updated though rest DB queries were running fine.I could't find proper solution but the way around was from mysql editor (like workbench) do inspect schema.
You will get an option in bottom to 'Information Outdated' and then click on Analyze table. You will find that Information_schema start calculating correct size and other details.

Imported Database not in Cpanel

I imported a database in phpmyadmin directly without creating a database in cpanel. I am not able to view the database in cpanel, nor can I delete it. Even the script fails to connect to it since I didn't specify a user for that database. Any help?
If I understand your question right, it's impossible. I've tried to import a database in phpmyadmin (version 3.5.1) directly without creating a database and got this message: "#1046 - No database selected".
You are not able to do anything with database, because it just doesn't exist.

how to change the username of a mysql database?

This may be a basic problem in the database world but I don't speak 'databaseian' fluently.
I am transferring a website from one hosting service to another; from server A to server B. Server B offers the service of transfer but I would like to do it myself. The website is based on WordPress.
My strategy is:
to copy all the files from one server (A) to the other one (B) (done).
to export the mysql database from server A into a .sql file (done).
import the .sql file into a new database in server B so now Wordpress can talk to MySql (here is the problem).
The hosting service in server B provides the phpMyAdmin where I can import a .sql file ,the problem is that the database in server A was using a particular username (defined by them) and server B has another one (which I cannot change).
Is there a way of editing the .sql file in order to change (add) the username to the one in server B so I can import it smoothly?
Note: I have the password for the .sql database and username as well.
Update: The error shown by phpMyadmin when trying to import the .sql file is:
#1044 - Access denied for user 'userServerB'#'localhost' to database 'db-server-A'
Many Thanks
UPDATE: Everything is working now. Apparently the .sql file had a line that was trying to create a new database itself. I got rid of this line and just used a pre-created database using all the rest of the .sql file and voila. Particular thanks to #daking963
The database username/password is not part of the dumped database sql. It is part of the connection authentication details. You used one username/password to connect to server A, and a different one to connect to server B. The sql file is independent of this.
So, first just log in to phpMyAdmin on server B using the username/password they provided. Then, import the sql by following these steps:
1. Select the database you want to import into (or create a new one).
2. Click on SQL tab at the top.
3. Click "browse" next to the file upload box and select your sql file.
4. Click go to start the import.
UPDATE: Regarding your update showing the error message. It is trying to import the sql into a database named db-server-A on server B. Open the sql file in a text editor, and replace all instances of db-server-A with the name of your database on server B. Then save and repeat the steps above.
Can you change the access details in the wp config file for the new server:
wp-config.php

How to put password in mysql database that you export using phpmyadmin

How do I do that? Is it possible? If it's not possible in phpmyadmin then can you tell me some alternative to achieve the same thing (putting a password to the mysql database that is being exported for backup)?
Passwords and permissions are stored in the database named mysql.
If you need to copy passwords you can dump and restore that database, but it will likely cause you problems, you can line by line restore from the database for tables that contain specific info.