How to work with emacs and mysql - mysql

I'm getting the message unable to locate SQL program 'mysql' when I attempt to enter sql mode in Emacs. However, I'm able to access mysql just fine via terminal.
For the record, I'm using user and password as root, server as localhost and a database of my choosing. I just don't know why this is happening.
Ideas?

Emacs uses the directories listed in the exec-path variable to look for programs. You can add to it like so:
(add-to-list 'exec-path "/usr/local/bin")
The following shell command should give you the correct value to use:
dirname `which mysql`

Related

Delphi + MySQL command line

I'm building a tool using Delphi and MySQL to restore a script generated with MySQLDump.
It was supposed to load and execute a SQL file and log any possible errors into a given output file.
I thought about execute the mysql command line and send command lines but i don't know if its possible ou how to do it since I just know how to call mysql using windows cmd and execute a single command line using ShellExecute or CreateProcess
I tried to do it with a single command line but it did'nt logged the errors properly
I tried this:
cmd /c mysql.exe --user root < "C:\restore.sql" > "C:\restore_log.txt"
the content of restore.sql was:
drop database test;
It does execute my script, but on the second attempt it should log "database doesn't exist" but restore_log.txt was empty
It would help if anyone could point the way to call mysql and send multiple lines OR a help with my cmd line to log properly
Anyone can help me?
I don't know what components you've got available to connect to the MySQL db, but using TADOQuery to access SQL Server, I simply load up the queries into a TADOQuery's .SQL property and then call Open or ExecSQL. As long as it's just vanilla SQL that was generated by SQLDump, I'd guess that should work. It's worth a try anyway.
digging more at stackoverflow I found previous answers that helped, the difference is that the output goes to a Memo that I can save to a file.
Thank you all for the help and the insights.
The answers can be found on the following links:
Getting output from a shell/dos app into a Delphi app
How do I run a command-line program in Delphi?
Getting output from a shell/dos app into a Delphi app

Error establishing database connection using wp-cli and xampp

I've got everything to work with WP-CLI on Windows running XAMPP. Or so I thought. When I try to execute the following command:
wp rewrite structure '/%postname%/'
I get the following error:
Error: Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we canÔÇÖt contact the database server at localhost. This could mean your hostÔÇÖs database server is down.
I've read that the PHP used needs to be correct (a usual explanation for this problem). Running wp --info yields the following results.
$ wp --info
PHP binary: C:\xampp\xampp-5.6.24\php\php.exe
PHP version: 5.6.24
php.ini used: C:\xampp\xampp-5.6.24\php\php.ini
WP-CLI root dir: C:\lib\wp-cli
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.0.0
I think that this looks correct. I can access the db from a browser, use WP normally, and even perform database commands using wp-cli. But for some reason, the rewrite command gives an error (as stated above). The fun thing is that it actually changes the permalink option, but I'm afraid that since it gives an error some other action is not performed correctly.
Changing the credentials in wp-config.php makes me unable to run db commands, so clearly it works at some level.
What might be wrong? I'm pretty clueless here!
The database is set up by using wp-cli and is accessed using the root account.
It turned out to be a bug in wp-cli, which the author is now working on.

Options for secure connection to mysql from bash script

I am trying to execute a few mysql statements in bash script. The script connects to mysql and does all the required work. But, it gives me a warning
Warning: Using a password on the command line interface can be insecure.
I understand that passwords and usernames must not be used directly in the script, which I have currently done
What other options do I have in order to not have this warning coming up? Can I have a file with the key:value pairs for host,dbname,username and password and then use the file for connection details in the script?
Thanks in advance
Rathi
During the init phase of your script, I would ask the user for host, username and password. Then forward these variables to the mysql command.
See here where you can learn how to ask the user for content without echoing it on the terminal window.

Connecting to mysql from cygwin issue

I am trying to debug something larger and I noticed that I can not properly connect to mysql from cygwin. I run the command by providing the host, user and password, and the only output is the error:
Warning: Using a password on the command line interface can be insecure.
after which it just idles.
interesting is that when i run
which mysql and I go to that path with the command prompt from windows and run the same command everything is ok.
Some console applications that weren't compiled using Cygwin may work incorrectly inside Cygwin's terminal. MySQL client is probably one of them. To use MySQL client with Cygwin, I'd install one from official Cygwin's repositories rather than trying to use native Windows MySQL. (Note that this doesn't mean installing whole server, just the client.)

No system command when using mysql from cli

Attempting to change directories, view directory contents, etc., but for some reason I don't have the system command to use the command line once I run mysql. These are the options I get:
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
notee (\t) Don't write into outfile.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog
with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
Any ideas what could cause this? It seems to be possible using windows (using \!).
As stated in the MySQL documentation, the MySQL system command works only in Unix and therefore not in Windows:
http://dev.mysql.com/doc/refman/5.6/en/mysql-commands.html