Exporting mysql database from wampserver using vb6 - mysql

Im having a problem exporting a mysql database from wampserver. Im using the following code:
Private Sub cmdBackup_Click()
Screen.MousePointer = vbHourglass
DoEvents
cmd = Chr(34) & "C:\Documents and Settings\Owner\Desktop\Documents\Clients\Darwin\mysql\mysqldump" & Chr(34) & "mysqldump.exe -uroot -p -hlocalhost school > c:\a.sql"
Call execCommand(cmd)
Screen.MousePointer = vbDefault
MsgBox "Done"
End Sub
As expected, an .sql file was created in my C:/. But for unknown reason, the created sql file is empty (literally empty, 0 byte, no texts inside).
Can someone help me? Thanks in advance! Sorry for my english.

I have no idea if that code should work its been years since I used VB6 but one obvious problem I can see is that when you execute this statement,
mysqldump.exe -uroot -p -hlocalhost school > c:\a.sql
the mysqlsump.exe will see the -p parameter and be expecting a password to be entered from the console. Try it manually from a command window!
I am guessing there is no console and if there was the user should not know the password to the root account anyway.
The quick solution would be to change the code to:
mysqldump.exe -uroot -pSuperUsersPassword -hlocalhost school > c:\a.sql
but that is a major security nightmare as you have hardcoded the MySQL Super Users password in a piece of code. Remember MySQL is a proper DBMS and can manage many different databases, not just the one you are using.
Also if the password is ever changed you must remember to change this code at the same time, a maintenance nightmare.
At the very least you should create a new user account in MySQL that has access to only this one database and has only the privilages to do backups (SELECT, SHOW DATABASES, LOCK TABLES, EVENT). Then at least you are not giving away the Crown Jewels to anyone that can see your source code or can read a hex dump of your executable.

Related

Download MySQL database from ISP server to localhost

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?

Database missing error

In my xampp,i could not start the MYSQL section.So XAMP re installed.Before reinstallation i keep database backup from the path C:\xampp\mysql\data.
After reinstallation paste datafolder content into this path.Then I tried to accessing phpmyadmin,then database and table names are listed there.But there is no content into each table.While clicking the database table, it shows an error table does not exist.Please give any solution for my this issue.Thanks in advance
Well, dumping DBs is pretty easy. I assume you are on localhost and your user name is root.
Make sure your MySQL server is up and running.
Run Command line and for dumping ALL your DBs, type:
mysqldump -u root -p --all-databases > dump.sql
Hit Enter. The system will ask you for a MySQL password, type it and hit enter. If there's no password set for your server, just hit Enter. Your dump file will be saved in the current directory.
To restore the dump (e.g. after you reinstalled MySQL), run Command line again and make sure you are in the same directory where your dump.sql is. Type:
mysql -u root -p < dump.sql
It will ask you for a password. You know what to do. Depending on how many data you have it can take some prolonged time. Hope it will help!
P.S. Dumping/restoring single DB is a little bit different, let me know if you need it and I will update this post.

uploading sql file via terminal

I am trying to import big .sql file using Terminal on Mac. What should be displayed after I run this:
mysql -u username –ppassword database_name < /path/to/file/file.sql
and hit enter? My database is still empty, the terminal doesn't show any errors, but it displays info about Oracle and the long list of Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
etc.
I had an error before saying 'Access denied for user... ' and the problem was CREATE DATABASE with old db name, I have amended it to the new db name, now there is no error, just long list of help.
Have anyone got an idea what could be wrong, and what this help list means?
I see you got your answer and fixed it. Here is an alternative to entering your username and password on the command line (often not considered a best practice, and tough to automate).
cd to /~
create .my.cnf
with the contents below
[mysql]
user=here_is_my_username
password=here_is_my_password
Then you can simply run commands like
mysql database_name < /path/to/file/file.sql

importing database from phpmyadmin to linode

I've been searching the web for a solution for a while now & just can't seem to get it with what i've found online. I've exported my phpMyAdmin database & uploaded it to my Linode so its now there ( /home/user_name/public/www.sitename.com/public/phpmyadmindatabase.sql )
So now in the terminal i'm entering the following:
mysql -u root -pMyPassword database_name < ~/public/sitename.com/public/phpmyadmindatabase.sql
and I get the following:
ERROR 1049 (42000): Unknown database 'database_name'
Now I'm wondering if i need to create 'database_name' first, but I'm following Linode's own start up guides:
http://library.linode.com/hosting-website#sph_installing-mysql
and they say right at the section "Creating a Database"...(If you already have a database you'd like to import...skip to "importing a database"). So i have been assuming i shouldn't be creating a database since it told me to skip it.
Any & all help would be greatly appreciated...
thanks,
Stupid mistake...just needed to create the new DB manually or make sure phpmyadmin is creating the DB in mysql when its added to the Linode.
On another note - Linode has pretty great customer support (guess that would be the first place to go).

Avoiding MySQL1044 error

I am trying to learn PHP and MySQL and while I reached a chapter on MySQL I was asked to create a database using this command:
CREATE DATABASE publications;
After I typed it in the mysql console I got this error:
ERROR 1044(42000):Access denied for user ''#localhost' to database 'root'
I am already logged in to my administrator account so I think the privileges should't be a problem.I have installed with the XAMPP package.
How can this be solved?
It could be possible that you upgraded your version of EasyPHP or you did something to disable the root password. If that is the case, you should try reestablishing a password for root. Had the same problem and that's how I solved it.
Go to http://localhost/xampp/ and set the appropriate passwords (in Security tab). If you use mysql client program, make sure you call it with appropriate credentials: mysql -u <username> -p <password>. Username will mostly be root until you create some new accounts.
Then I suggest you use phpMyAdmin for experimenting with MySQL (it should be at http://localhost/phpmyadmin/ )
This is getting a little confused - let me try to answer this.
Mysqladmin is a command line client for administering your mysql database system - you normally don't need to run it once you have mysql working. The shell command line interface to the mysql server is mysql. (If you don't know how to run a shell command line, that's another problem. Also, if you're on Windows, say so, since that has its own challenges.) The arguments are:
mysql -u username -ppassword databasename
if you are running this command on the same server as mysql. Note the lack of space after the -p - that is important.
So, type the above line to invoke the command line interface to mysql. Then you can type your mysql commands. Things like show tables, desc tablename, etc., will work. That is they will work unless you have an authentication problem. But you will know you have an authentication problem because when you tried to run mysql as above, it will fail with some error, like "Access denied for user 'abc'#'localhost' (using password: YES)". This is a nice descriptive error message that points you exactly where the problem is.
Does that help?
You can go back to using xampp or anything else once you've made sure that you know the right parameters by checking with the command line. (Always check with the command line when strangeness happens - it's so much easier than trying to debug through other interfaces.)