mysqlcheck does not accept password - mysql

According to the mysqlcheck manual I can do the following:
mysqlcheck datatabase_name --auto-repair -ao -u="user" -p="password"
However it never accepts the password. It does not matter whether I use the shell or database login. When I leave the password, i can connect after it prompts me to put the password. I want to put it in a cron script so i need to be able to put the password inside the command.
Also am i right that this command will analyse, optimise and repair if needed?

Try using:
mysqlcheck datatabase_name --auto-repair -ao --user=user --password=password
or -uuser or -ppassword should also work.
Unfortunately I can't really provide any further insight into your queries on how effective mysqlcheck actually will be in what you want it to do. I suspect it won't do the things that will really improve DB performance though like adding well placed indexes and optimizing queries to only link where necessary.

Related

Can't add MySQL database to ClearDB, -u command not found

Doing the following, I am unable to import a MySQL database to ClearDB:
$mysql -u b4587523b48993 -h us-cdbr-iron-east-05.cleardb.net -p heroku_571df93b7623da9 < ./sql/sql_import.php
Whenever I try I get the error
-u: command not found
If I put sudo in front it says:
sudo: unknown user: b4587523b48993
sudo: unable to initialize policy plugin
Any ideas as to why this is happening?
Before doing anything else, please invalidate those connection credentials and generate new ones. They're forever compromised.
The entire command you're running, from -u to the end, should be arguments to the mysql command. Your $mysql shell prompt may make it look like that's what you're doing, but it isn't.
Add mysql to the beginning of your command (and adjust to account for your new credentials):
$mysql mysql -u b4587523b48993 -h us-cdbr-iron-east-05.cleardb.net -p heroku_571df93b7623da9 < ./sql/sql_import.php
As a side note, it's probably a good idea to lose the habit of prefixing sudo to commands that don't work. It's fine to do this in some situations, but it's important to recognise them. It shouldn't be your default troubleshooting action.

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.

Security of passwords in bash subcommands

I've heard that directly inputting your password on the command line is a bad idea, because anyone could see the "secret" in
mysql -u root -psecret
by browsing history.
I have a password for my MySQL database stored in a text file with limited read permissions, and was wondering if it is safe to access it in the following way:
mysql -u root -p$(cat ~/.mysql_pass)
Browsing history, I see the command printed, not the literal value. So it seems like it's working the way I want it to.
I'm sure there are better ways of handling passwords, I would just like to know whether or not this one is leaving my password completely out in the open.
You've suggested using the following:
mysql -u root -p$(cat ~/.mysql_pass)
However, the subcommand will be expanded before mysql is executed and so even if this isn't available in the command history, it's entirely possible for someone to view the process list just after invocation and see your password.
I think a better approach is to use a mysql client options file and have the mysql command read the password from the options file.
Just type mysql -u root -p and you'll get a prompt to enter your password and it won't be stored in the history.

logging into sql

I am a student learning sql and working an assignment to set up a database in mySQL 5.5 community version. The command I am given does not work as detailed. Here is what I have done so far:
This is the command that I am told to use after setting up mySQL 5.5.
mysql –h localhost –u root -p
This brings back a long screen of help commands. I found out that instead I need to use:
mysql -u root -p. Then I get my password prompt that works. That starts sql. Next I was given these statements to create a user named user1.
USE mysql;
create user ‘user1’#’localhost’ identified by ‘user1’;
grant select, insert, update, delete, create, drop, references, execute on *.* to ‘user1’#’localhost’;
exit
I entered these line by line and they seem to work. No errors are returned. However when I try to start the user with the following commands:
Login as user1
mysql –h localhost –u user1 –p
password is user1
I get a long list of help commands when i exexute the mysql line.
What is incorrect with the commands I have executed and also why? I initially think it may be that these commands were written for an earlier version? I was initially told to reinstall mysql and did that with no errors. I get the same results as before reinstalling it. If I need to explain or add screenshots, I will be glad to do so.
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
mysql -h localhost -u user1 -ppassword database_name_here
Your other option:
mysql -h localhost -u user1 -p database_name_here
But for the second one you will have to type the password.
Sorry for not answering you question specifically, but I recommend you to get an interface to mySQL which makes it all a bit easier. In my case I still use the terminal to perform some queries once in a while, but for user management and to get a better presentation I use phpMyAdmin which makes the whole process much more neat. Good luck!

MySQL: Why does basic MySQLdump on db table fail with "Permission denied"

This should be quick and simple, but after researching on Google quite a bit I am still stumped. I am mostly newbie with: server admin, CLI, MySQL.
I am developing my PHP site locally, and now need to move some new MySQL tables from my local dev setup to the remote testing site. First step for me is just to dump the tables, one at a time.
I successfully login to my local MySQL like so:
Govind% /usr/local/mysql/bin/mysql -uroot
but while in this dir (and NOT logged into MySQL):
/usr/local/mysql/bin
...when I try this
mysqldump -uroot -p myDBname myTableName > myTestDumpedTable.sql
..then I keep getting this:
"myTestDumpedTable.sql: Permission denied."
Same result if I do any variation on that (try to dump the whole db, drop the '-p', etc.)
I am embarrassed as I am sure this is going to be incredibly simple, or just reveal a gaping (basic) hole in my knowledge. .. but please help ;-)
The answer came from a helpful person on the MySQL list:
As you guys (Anson and krazybean) were thinking - I did not have permission to be writing to the /usr/local/mysql/bin/ dir. But starting from any other directory, calls to mysqldump were failing because my shell PATH var (if I said that right) is not yet set up to handle mysqldump from another dir. Also, for some reason I do not really understand yet, I also needed to use a full path on the output, even if I was calling mysqldump effectively, and even if I had permission to write to the output dir (e.g. ~/myTestDumpedTable.sql. So here was my ticket, for now (quick answer):
Govind% /usr/local/mysql/bin/mysqldump -uroot -p myDBname myTableName > /Users/Govind/myTestDumpedTable.sql
You can write to wherever your shell user has permission to do so. I just chose my user's home dir.
Hope this helps someone someday.
Cheers.
Generally I stick with defining the hostname anyways, but as you being root doesn't seem like it would be the problem, I would question where are you writing this to? What happens when you dump to > ~/myTestDumpedTable.sql
Even I was facing the same problem, the issue is with user access to 'root/bin' dir.
switch your user access as root
sudo -s
Then execute the command
mysqldump -uroot -p homestayadvisorDB > homestayadvisor_backup.sql
This will resolve the issue. Let me know if this doesn't work.
Take a look at the man page for mysqldump for correct argument usage. You need a space between the -u flag and the username, like so:
mysqldump -u root -p myDBname myTableName > myTestDumpedTable.sql
Alternatively you can do
mysqldump --user=root -p myDBname myTableName > myTestDumpedTable.sql
Since you're not providing a password in the list of arguments, you should be prompted for one. You can always provide the password in the list of arguments, but the downside to that is it appears in cleartext and will show up in the shell's command history.
In my case I'd created the directory with $ sudo mkdir /directory/to/store/sql/files. The owner of that directory is root. So changing the owner by using $ sudo chown me:me /directory/to/store/sql/files and also changing permissions to maybe $ sudo chmod 744 /directory/to/store/sql/files did the trick for me.
mysqldump don't work with sudo, if you are using
sudo mysqldump then try below solution:
sudo su
mysqldump -u[username] -p[password] db_name > newbackupfile.bkp
You should provide with a full path for SQL backup file, such as
mysqldump -u root -p databasexxx > /Users/yourusername/Sites/yoursqlfile.sql
I think you're missing the ./ from the command, try:
being inside
/usr/local/mysql/bin$ ./mysqldump -u root -p myDBname > "/Users/yourUserName/Documents/myTestDumpedTable.sql"
So it is a script, and in linux you execute a script with ./myscript.
I found it just today, and for me, in my mac OSX, I didn't use the -p, maybe because password not needed, don't know already. I mean, try also:
./mysqldump -u root myDBname > "/Users/yourUserName/Documents/myTestDumpedTable.sql"