# [SOLVED] After copy Mysql DB to new server, no root access

## bastibasti

Hi Iam running a bugzilla. I got a new machine, and copied the /var/lib/mysql folder to the new machine. 

Now I tried to add another user.

```

server ~ # mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

```

any advice?Last edited by bastibasti on Sun Mar 06, 2011 9:03 am; edited 1 time in total

----------

## cach0rr0

'tis not the best way to copy over databases, especially after a handful of storage engine changes that happened in the past recent history

if you must do things this way, start mysql in safe mode, change the password, see how you get on

if you're happy to redo things

-unmerge mysql

-re emerge mysql

-run mysql_install_db

-run mysql_secure_installation

-backup your databases from the old server via mysqldump

-import them onto the new server by hand via regular old mysql command-line

----------

## bastibasti

Thanks. Is there a howto for doing this? Mysql is not one of my best knowledged items

----------

## cach0rr0

 *bastibasti wrote:*   

> Thanks. Is there a howto for doing this? Mysql is not one of my best knowledged items

 

hrmm...i dont know of a howto doc offhand, but i can give the basic commands

say you have a backup on your old server called, i dont know, 'gentoo'

to move it from old server to new:

on the old server:

```

mysqldump gentoo > gentoo.sql -p

(enter your root pass when prompted)

```

copy gentoo.sql over to the new server, then

On the new server:

```

mysqladmin create gentoo -p

(enter password when prompted)

mysql gentoo < gentoo.sql -p

(enter password when prompted)

```

if you used a different login to connect to this database other than root on the old server, you will  need to set that back up

```

mysql -p

(enter root mysql pass when prompted)

mysql> grant all privileges on gentoo.* to 'gentoo'@'localhost' identified by 'whateveryouwantthepasswordtobe';

mysql> flush privileges;

```

That assumes you will be connecting to the database via localhost of course. 

And now all of this assumes that you have already emerged mysql, run 'mysql_install_db', then started mysql and run 'mysql_secure_installation'

Those two commands will have on-screen instructions, that should be fairly self-explanatory. 

You used to get a message from emerge after mysql was installed, saying "please run emerge --config=dev-db/mysql-5.1.x.whatever_version", which would do all of this for you. For some reason it seems this does not get shown any more. 

Anyway, before you do anything else, unmerge mysql, and make sure /var/lib/mysql is empty. Then emerge mysql, run those two commands, and start moving your databases over via mysqldump and then the mysql dbname < backupfile.sql stuff.

----------

## bastibasti

Thanks, I'll give it a try!

----------

