I have an install script that can create a db, with
(sql ddl)create database if not exist.
Since Postgres works differently the script doesn't work.
So I build a special case for Postgres and used the
(commandline) createdb -U ... command for generating a database.
It works so far, but Postgres requests the password a second time.
Following this thread i found out that
I can provide the password with the var PGPASSWORD
Following this thread i came up with a solution:
(php)
exec(' set PGPASSWORD=$password && createdb -U "$username" -h "$host" "$dbname" ')
(simplified escapes)
but this returns an error:
createdb: could not connect with template1: FATAL: Password authentication for user »postgres« failed (translated)
I am not familiar with commandline and its characteristics ->
I am not sure if I did a grave unnoticed misstake there, i am sorry if i did
I will implement now a version where Postgres asks the user a second time,
but it would be cool if you find a solution where the user doesn't have to type password twice
Why use an operating system command? You can do the same thing with SQL: Simply connect to the postgres database (or any other database) and run
CREATE DATABASE dbname
Related
I'm new to Ubuntu. I tried to run a .php file and connect it to a database. Everything is on-set. I already imported the database in phpMyAdmin but every time I access my database,it returns an error
This page isn’t working localhost is currently unable to handle this
request. HTTP ERROR 500
Turns out, it seems like my database isn't running at all. In Windows I just open the XAMPP and click Apache and MySQL buttons. While in Ubuntu,
I have no idea on how to start or run MySQL and Apache. I already tried running commands on the terminal but it won't help. Someone has already installed it on this computer, I just don't how to run it and what web-server platform is this running.
How do I do it and how would I know that my database is running and accessible?
Try to connect your database and access database via command line.
mysql -u [username] -p
you can replace [username] with your real username of mysql like root
it will prompt for password so you are type yours like root
prompt will say
mysql>
now you need to list all databases to see is database exists or not
show databases;
it will list down all databases. you may verify is your exists or not
then you can select database by
use databasename;
and then run
show tables;
it will show all tables.
so you can verify that mysql working, database exists and tables are there or not.
Use this command it will start the database is you have it
systemctl mysql start
This should do the trick you need to have mysql database or maria db installed
Check by running this command in terminal after the first one
mysql
And you can also add argument like host and login
mysql -h (your host default is localhost) -u (user default is root) -p (password default is none)
Check your files access level
sudo chmod -R 777 "location of your file"
I am importing a MySQL database from another server to my own server using phpMyAdmin. But the problem is:
I go into import then choose a file which have extension like .sql, .xml. After this procedure I click on the ok button but this doesn't give any response and doesn't even do anything, the page just remains stable.
I also tried with MySQL command prompt using mysqldump.
mysqldump -u username -p databse > database name
but this is also giving an error.
Can any one please help me in solving this?
This command is used to export :
mysqldump -h hostname -u username -p database > sql_file_name
to import you should use
mysql -h hostname -u username -p database < full_file_path
first you need to export a DB from the first server.
on your server you first need to create a new DB and than do the import.
the DB you imported will go to the DB you just created.
I am attempting to import my ClearDB database in Heroku by running the command in the window:
mysql -u REDACTED -h us-cdbr-iron-east-02.cleardb.net -p REDACTED < C:/Users/KJA/Downloads/androidchatterdatabase.sql
After inputting the password, the error appears as:
ERROR 1227 (42000) at line 27: Access Denied; you need (at least one of) the SUPER privilege(s) for this operation
Then when seeing what the login is that would require the privileges it notes as:
Is there an alternative host address to use? How can I send my database schema to ClearDB in Heroku and run?
You need to select a database to work on by passing that as an argument to the command; you don't have privileges for any operation without a database (because that would let you control things at the "server level", not the database level).
Your command needs to be mysql -u YOURUSERNAME -h us-cdbr-iron-east-02.cleardb.net -p YOURPASSWORD heroku_XXXX < C:/Users/KJA/Downloads/androidchatterdatabase.sql (or whatever your database name is; I took "heroku_XXXX" from one of your other questions).
Recently, I've started using openshift & also deployed an application using PHP & MySQL. Yesterday, out of curiosity, I've removed the password for phpMyAdmin and guess what, now I'm unable to log in to both phpMyAdmin & mysql database.
I've tried both the passwords (the default one & the empty password) and uninstalled & re-installed the PHPmyAdmin catridge & also, force restarted the app several times but nothing worked. Now, I've no idea what happened. Any help is appreciated.
Hopefully this will help.
I assume what you did was go into phpmyadmin and click on 'users' then 'edit privileges' for one of the users, select 'no password' and hit save right? If so, then I think the following steps should help.
1.) ssh into your gear (you can use the rhc ssh command)
2.) run the mysql command
3.) You should get an error like this ERROR 1045 (28000): Access denied for user 'adminslULJTS'#'127.10.126.130' (using password: YES)
4.) Now, type in the command mysql -u $OPENSHIFT_MYSQL_DB_USERNAME -h $OPENSHIFT_MYSQL_DB_HOST -P $OPENSHIFT_MYSQL_DB_PORT -p
5.) When it asks for a password, just hit enter
6.) You should now be logged into the mysql shell
Now you need to reset your password to what openshift thinks it is.
1.) create another ssh session into your gear in another terminal, leaving the old one open
2.) run the command env | grep MYSQL
3.) this will give you the following information that you will need to reset your password:
OPENSHIFT_MYSQL_DB_HOST=127.10.126.130
OPENSHIFT_MYSQL_DB_PASSWORD=Il8-rVLIKSrx
OPENSHIFT_MYSQL_DB_USERNAME=adminslULJTS
Given the above information, go back to your ssh session that had the mysql connection open, and enter the following command:
set password for 'adminslULJTS'#'127.10.126.130' = PASSWORD('Il8-rVLIKSrx');
But you will need to replace the username, host, and password with the ones you got from the above step.
You should now be able to log into phpmyadmin with your old username & password that you can either view using the env | grep MSYQL command, or view in the web console for your application at openshift.com
It also might be worth reviewing this KB article: https://www.openshift.com/kb/kb-e1085-possible-complications-when-changing-your-database-credentials
I'd like to have a properly protected PHP web-based tool to run a mysqlcheck for general database table health, but I don't want the password to be visible in the process list. I'd like to run something like this:
$output = shell_exec('mysqlcheck -Ac -uroot -pxxxxx -hhostname');
// strip lines that's OK
echo '<pre>'.preg_replace('/^.+\\sOK$\\n?/m', '', $output).'</pre>';
Unfortunately, with a shell_exec(), I have to include the password in the command line, but am concerned that the password will show up in the process list (ps -A | grep mysqlcheck).
Using mariadb 5.5 on my test machine, mysqlcheck doesn't show the password in the process list, but my production machine isn't running mariadb and running a different OS and I'd like to be on the safe-side and not run these tests on the production side.
Do all versions of mysql also hide the password in the process list? Are my concerns a non-issue?
Yes, since at least MySQL 5.1, the client obscures the password on the command-line.
I found this blog by former MySQL Community Manager Lenz Grimmer from 2009, in which he linked to the relevant code in the MySQL 5.1 source. http://www.lenzg.net/archives/256-Basic-MySQL-Security-Providing-passwords-on-the-command-line.html
You could alternatively not pass the password on the command-line at all, and instead store the user/password credentials in a file which PHP has privileges to read, and then execute the client as:
mysqlcheck --defaults-extra-file=/etc/php.d/mysql-client.cnf
The filename is an example; you can specify any path you want. The point is that most MySQL client tools accept that --defaults-extra-file option. See http://dev.mysql.com/doc/refman/5.6/en/option-file-options.html for more information.
It is a real concern and your OS will be showing it, Just not maybe in the default view.
You could proc_open instead which will allow you to read and write to the stream opened by that file.
mysqlcheck -Ac -uroot -p -hhostname
will prompt for the password which you can write to with the pipes from proc_open