I have an user called root and his password is "12233" in localhost
How I enter to mysql from the Ubuntu's console?
mysql -u root -p
And after it will ask you your password just type it in and that's it.
From the command line:
mysql -u [username] -p [password] [dbname]
for example:
mysql -u myuserid -p mypassword mainDB
This will give you access into mysql and then you can run different commands within the MySQL shell, like:
use mainDB --->select the DB you want to work on
select * from tablename; ---> get all records form the table table name
Hope this helps.
Related
I want to import database in phpmyadmin mysql from terminal ubuntu. Can anybody give me command to insert such large size database?
Thanks. I got my answer.
First of all, write into termial as
$ mysql -u (username) -p (password)
Example, $ mysql -u root -p root
then, it will be like
mysql> use db_name;
Example, mysql> use my_database
then enter your source path.
mysql> source backup-file.sql;
Example, mysql> use /home/kazim_noorani/database_file.sql
I have create a new user in pgsql with no password. But when i try to create a database for this user it prompts for a password
>createuser -d -S -R -U postgres test1
Password:
>createdb -U test1 db1
Password:
i have tried the superuser password but it gives me the error :
createdb: could not connect to database template1: FATAL: password authentication failed for user "test1"
Please help,
Thank you
There is an alternative way to create user by prompting password.
You can give -P option while creating user.
Like:
createuser -d -S -R -U postgres test1
This may work for you,
psql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"
You need to run this from command-prompt. Go to the PostgreSQL folder where you can find the program psql and try this command. mydb would be the database name.
Reference: How to prevent asking for password when creating new database in PostgreSQL 10?
Thanks to: Jasen and Mladen Uzelac
I want to set up the psql terminal tool in Centos 6.6
I have been given access to as database and i just want to use the terminal for writing queries to the database for information. I have no prior experience with psql before but I want to move on from the pgadmin3 gui.
I started off by installing psql:
yum install postgresql
but when I try to access it, ie. typing [root#localhost]# psql I get the following error:
psql: FATAL: database "root" does not exist
I've tried using:
psql --host=<DB instance endpoint> --port=<port> --username=<master user name> --password --dbname=<database name>
but that fails to work too, maybe this is really basic but im completely lost for setting this up
Use:
psql -U my_pgadmin_username postgres
or
psql -U my_pgadmin_username -h localhost postgres
Alternately, more typical usage:
sudo -u postgres psql
I am trying to copy one table from one database to another:
sudo -u postgres pg_dump -t _stats db30 | psql db8;
However, I always get asked for a password, and I do not know what it is. Is there a way to do this without pg_dump? Is there a way so that I can not be asked for a password when I run psql?
Note, to get into postgres I have to run sudo -u postgres psql instead of psql
User management and permission on a postgres server is a complex topic, but you have probably only a server installed on your desktop and use it only on localhost, so security is not so important.
You have to do 3 steps:
1) Edit the pg_hba.conf file and restart the server
2) Login with psql and set a password for the user postgres
3) Edit (or create) the file ~/.pgpass
NOTE: you could use the authentication method trust in pg_hba.conf and avoid the step 2 and 3, but this is really TOO permissive, and you shouldn't use it, even on localhost.
The pg_hba.conf file
To understand the file pg_hba.conf please read here: http://www.postgresql.org/docs/9.4/static/auth-pg-hba-conf.html
Basically, if you server is on localhost and security does not matter, you can simply allow all user to connect with md5 authentication method.
If you don't know, where this file is, use this command:
locate pg_hba.conf
Probably is in /etc/postgresql/9.3/main/pg_hba.conf or similar.
Edit the file and change the already existing lines so (at end of the file):
local all all md5
host all all 127.0.0.1/32 md5
Now restart the server with
sudo service postgresql restart
Set a password for the user postgres
First login in psql:
sudo -u postgres psql
Now, within psql, change the password:
ALTER USER postgres PASSWORD 'your-password';
The pgpass file
Now you can login in psql with psql -U postgres (without sudo -u postgres) but have to enter the password. To avoid to digit the password every time, you can set up the pgpass file. If does not already exist, you must create a file named .pgpass in your home directory. The file must be owned by your user and be readable only by your user:
chown $USER:$USER ~/.pgpass
chmod 600 ~/.pgpass
Now write in the file those lines:
localhost:5432:*:postgres:your-password
127.0.0.1:5432:*:postgres:your-password
Alternately you can use the environment variable PGPASSWORD: http://www.postgresql.org/docs/9.4/static/libpq-envars.html
Ready. Now you can login in postgres with psql -U postgres without enter the password.
I have a database file on my desktop that I am trying to open through my terminal.
my database is called: myDB.db
I tried using:
mysql -u myDB.db -p
Thank you!!!
SOLVED for mysql! (Thank you Duffymo)
mysql -h localhost -u -p
>use [databaseName];
Also for sqlite you can do it this way:
sqlite3 [databaseName]
>.tables
I use the command line this way:
http://dev.mysql.com/doc/refman/5.6/en/mysql.html
mysql -h localhost -u <admin user name> -p
I'm prompted for the admin or user password.
When I get into MySQL I specify which database I want to work with:
use X;
where X is the name of the schema I'm interested in.
At that point I can execute SQL commands.