1、安裝前修改/etc/my.cnf,加入datadir = /data/mysql/ 再執行sed -i 's/skip-locking/skip-external-locking/g' /etc/my.cnf 之后的命令,將里面的給目錄加權限修改為你新的目錄
2、安裝后
停止mysql,移動/usr/local/mysql/var/ 到新目錄,修改/etc/my.cnf ,查找[mysqld] ,在下面加入datadir = /data/mysql/ ,給新目錄加權限,重啟。
注意,修改前先備份數據!!!!
我是安裝后修改/etc/my.cnf 出現 MySQL: Starting MySQL….. ERROR! The server quit without updating PID file
按下面方法,等於重新安裝了mysql,數據都沒了。
1 問題
[root@localhost mysql]# /etc/rc.d/init.d/mysql status
MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]
[root@localhost mysql]# /etc/rc.d/init.d/mysql start
Starting MySQL...The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid). [FAILED]
2 原因
沒有初始化權限表
3 解決辦法
#cd /usr/local/mysql(進入mysql安裝目錄)
#chown -R mysql.mysql .
#su - mysql
$cd server
$scripts/mysql_install_db
4 本人解決過程
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# chown -R mysql.mysql .
[root@localhost mysql]# su - mysql
[mysql@localhost ~]$ cd /usr/local/mysql
[mysql@localhost mysql]$ scripts/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
[mysql@localhost mysql]$ /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 11767
[mysql@localhost mysql]$ 120502 07:01:17 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
120502 07:01:17 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[mysql@localhost mysql]$ /etc/rc.d/init.d/mysql status
MySQL running (11830) [ OK ]
[mysql@localhost mysql]$ /etc/rc.d/init.d/mysql start
Starting MySQL [ OK ]
上面成功后,改數據庫密碼
Linux下修改Mysql的用戶(root)的密碼
修改的用戶都以root為列。
一、擁有原來的myql的root的密碼;
方法一:
在mysql系統外,使用mysqladmin
# mysqladmin -u root -p password "test123"
Enter password: 【輸入原來的密碼】
方法二:
通過登錄mysql系統,
# mysql -uroot -p
Enter password: 【輸入原來的密碼】
mysql>use mysql;
mysql> update user set password=passworD("test") where user='root';
mysql> flush privileges;
mysql> exit;
二、忘記原來的myql的root的密碼;
首先,你必須要有操作系統的root權限了。要是連系統的root權限都沒有的話,先考慮root系統再走下面的步驟。
類似於安全模式登錄系統,有人建議說是pkill mysql,但是我不建議哈。因為當你執行了這個命令后,會導致這樣的狀況:
/etc/init.d/mysqld status
mysqld dead but subsys locked
這樣即使你是在安全模式下啟動mysql都未必會有用的,所以一般是這樣/etc/init.d/mysqld stop,如果你不幸先用了pkill,那么就start一下再stop咯。
# mysqld_safe --skip-grant-tables &
&,表示在后台運行,不再后台運行的話,就再打開一個終端咯。
# mysql
mysql> use mysql;
mysql> UPDATE user SET password=password("test123") WHERE user='root';
mysql> flush privileges;
mysql> exit;
##本來mysql是不分大小寫的,但是這個是修改的mysql中的mysql數據庫的具體的值,要注意到。
