ubuntu建站遇到的mysql数据库问题

           将源站所有代码和数据拷入/var/www目录下,通过浏览器访问127.0.0.1访问时看不到正常页面,报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)可以看出mysql出错了,在终端控制器下登录mysql也报该错误。解决办法如下:

root@bt:~# cd /usr/bin
root@bt :/usr/bin# /usr/bin/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:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h bt password 'new-password'

Alternatively you can run:
/usr/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 /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/scripts/mysqlbug script!

The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/ 

root@bt :/usr/bin# cd /usr 
root@bt :/usr# /usr/bin/mysqld_safe &
[1] 2639
root@bt :/usr# 120710 07:40:51 mysqld_safe Logging to syslog.
120710 07:40:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

root@bt :/usr# /usr/bin/mysqladmin -u root password 'root'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)' 

 

  如上,一步步输入命令,从上面可以看到输完命令最后尝试登录时,又报另一个错误:error: 'Access denied for user 'root'@'localhost' (using password: NO)'。解决办法(参考网址:http://www.jb51.net/LINUXjishu/10981.html)如下:直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码。具体命令如下:

 

root@bt :/# vi /etc/mysql/debian.cnf
root@bt :/# mysql -udebian-sys-maint -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> UPDATE mysql.user SET Password=PASSWORD('root') where USER='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.01 sec)

mysql> quit 
Bye

上面命令执行完成后,就可以以root用户(密码:root)登录,当然密码可以在上面的命令中设成其他的值。登录结果如下:

root@bt :/#  mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show datebases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datebases' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)



你可能感兴趣的:(ubuntu建站遇到的mysql数据库问题)