Mamp: import large database - macos

I'm importing a large drupal database to my mac using mamp and I keep finding errors, the phpmyadmin can't import the database. can anyone help me?

Importing a large database through phpmyadmin is not recommended (it will typically hangup forever). It's much more efficient to use the command line through the Terminal.
First, make sure you can connect to your database from the command line with one of the following commands:
1/ If your root password isn't set:
mysql -u root
2/ or if you have a root password:
mysql -u root -p
3/ or if you have a specific username and password:
mysql -u username -p
If one of those commands execute correctly, you're good to go to the next step.
Notice you can exit the mysql interactive session anytime with entering:
exit
List your databases:
SHOW databases;
If you don't have your database listed here, you will need to create it:
CREATE DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci;
Then select your database:
USE database_name;
Finally, import the data from your sql file:
SOURCE "path/to/your/file.sql"
Second method (it suppose your database is already created)
mysql -u username -p database_name < path/to/your/file.sql

Related

Postgres easy login with pgpass and alias not working

I am trying to use a one word alias to access a postgres database, the problem I am having is it needs a carriage return to work. Can anyone help me to get it to log in without the carriage return?
This is my alias which is in an environment file I am dotting:
alias pgres='psql --host cloudpoc.test.com.au -p 8367 -U kevin -W kev_db'
This is my .pgpass file which is in the users home directory:
cloudpoc.test.com.au:8367:kev_db:kevin:kevpass123
If I type "pgres" then I get a prompt for a password. I have to hit enter again to log in.
Shouldn't it just log me straight in?
Prompting for a password is what -W is for. If you don't want that behavior, then don't use -W.
You can specify the database connection parameters in a postgresql service file called ~/.pg_service.conf in you home. Based on your connection string:
cloudpoc.test.com.au:8367:kev_db:kevin:kevpass123
You would enter the following in ~/.pg_service.conf:
# Kevin's database service
[kev]
host=cloudpoc.test.com.au
port=8367
user=kevin
dbname=kev_db
password=kevpass123
And you would then connect to the database with:
psql service=kev

Role "postgres" doesn't exist on Windows 7

When running the following command after pg_ctl initdb and pg_ctl start commands:
C:\Program Files\PostgreSQL\11\bin>psql.exe -U postgres -h localhost
I am getting the following error:
role "postgres" doesn't exist
All similar questions are about Linux or Mac and they don't help me much, so I don't know how to fix it.
Since you didn't specify a username with -U when you ran initdb, the bootstrap superuser has the name of the operating system user with which you ran initdb.
So you can simply connect with
psql
If you would like to change the name of the user to postgres, that is simple:
-- get the name of the current user in a variable
SELECT current_user \gset
CREATE ROLE dummy SUPERUSER;
-- connect as user "dummy"
\c - dummy
-- rename the bootstrap user to "postgres"
ALTER ROLE :"current_user" RENAME TO postgres;
-- remove "dummy"
\c - postgres
DROP ROLE dummy;
-- disconnect
\q

Can I run a pg_dump automatically removing reference to the owner?

I want to be able to clone the contents of our postgre production database to an ownerless local database efficiently. I've successfully done this, but it was a laborious process with the following steps
$ pg_dump [prod_db] > tempfile
[Go through tempfile manually removing all 60ish references to the owner, named 'postgres']
$ cat tempfile > psql [local_db]
Otherwise when I ran the last step, I got a bunch of SQL error messages saying ERROR: role "postgres" does not exist. I tried recreating the local db with a matching 'postgres' owner, but a) I still got the same type of errors, and b) I don't want to have an owner set for my local database if it means I'll have to log into it.
Is there a best practice/efficient way of doing this if I want to re-clone it in future?
Use the -O switch to not have an owner defined in the dump.
Not having an owner set is not normal Postgres design. To avoid having to login to your postgres database you can setup a .pgpass file. This is a plain text file and should be set with 600 permissions. The contents will look like:
hostname:port:database:username:password
Each connection can be on one line.
Additionally, for local db connections, assuming you have setup the rest of your security properly (ssh certs, etc) you can edit your pg_hba.conf file and set local connection authentication method to "trust." This is obviously not recommended for production or sensitive data. The line would look like this:
local all all trust
The default method is "peer". Unless you set your username in a .pgpass file you will still need to connect with psql -U postgres but you will not need to enter a password.

Access Denied for User ODBC # localhost

i have installed Mysql on Windows7, i used mysql with mysql command line client & i also use Mysqldump in windows cmd, & it was working without any problem. But today, i tried to export database using mysqldump with this command in cmd
mysqldump –u root -p mypassword db_name > f:\mydb.sql
i tried many other commands and i always see error
Access Denied for User 'ODBC'#'localhost' (using password: yes) when trying to connect
as you can see, in mysqldump command i am using root as user then why i get user ODBC error ? one more thing, using mysql command line client i am still using mysql normally without any problem using root as user. i also tried to login in cmd with this command
mysql –u root -p mypassword
but still same error. and my password is 100% correct. kindly tell me how to solve this problem. Thanks
Have you tried storing pass in the cfg file? http://dev.mysql.com/doc/refman/5.7/en/password-security-user.html
try from command line:
mysql -u root -p
and then, when you are being asked for password, just type it.
Try the same with mysqldump command without typing your password after -p.

How to export 4 million data in MySQL?

I have a database with one particular table having more than 4 million record entries. I tried downloading whole db it using MySQL workbench as well as command terminal using following command:
mysqldump -u root -p password mydb > myfile.sql
But, I got only half of the data downloaded. If I ignored that one particular table, then it's working fine. Can anyone suggest me how to download db with tables having more than million entries?
Try adding the below lines in the my.cnf and restart
[mysqld]
# Performance settings used for import.
delay_key_write=ALL
bulk_insert_buffer_size=256M
or
mysqldump -u root -p --max_allowed_packet=1073741824 --lock-tables=false mydb > myfile.sql

Resources