ºìÁªLinuxÃÅ»§
Linux°ïÖú

ÔÚLinuxÏ°²×°mysqlµÄ¶þ½øÖÆÔ´´úÂë°ü

·¢²¼Ê±¼ä:2008-09-26 00:06:24À´Ô´:ºìÁª×÷Õß:velcbo
Ô­´´×÷ÕߣºÑÕ³¬

Õ⼸ÌìÑо¿Á˺þã¬ÖÕÓÚ±»ÎÒÖªµÀÁËÈçºÎÔÚLinuxÏ°²×°mysqlµÄ¶þ½øÖÆÔ´´úÂë°ü£¬×îÖÕ½â¾öÁËERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)µÄȨÏÞÎÊÌ⣬ÕæµÄÊǸп®Íò·Ö°¡£¬Ö»Ïë°ÑËûд³öÀ´£¬ÈÃ×Ô¼ºÒÔºó²»ÒªÍü¼ÇÁË£¬ºÃÁË£¬·Ï»°²»¶à˵ÁË£¬¿´¿´Îҵݲװ²½Öè°É£¡

1.ÏÂÔØmysql-5.0.51a-linux-i686-glibc23.tar.gz£¬ÏÂÔصØַΪhttp://download.unix-center.net/mysql/mysql-5.0.51a-linux-i686-glibc23.tar.gz
2.°ÑÏÂÔصÄÎļþ·ÅÔÚÄãµÄÖ÷Ŀ¼£¬ÔÚÖÕ¶ËÊäÈëls,ÈçÏÂ:
[root@localhost mysql]# ls
Desktop Documents Download Music mysql-5.0.51a-linux-i686-glibc23.tar.gz Pictures Public Templates Videos
3.È»ºóÓÃtar -zxvf mysql-5.0.51a-linux-i686-glibc23.tar.gzÃüÁî½âѹµ½µ±Ç°Ä¿Â¼£¬ÈçÏ£º
[root@localhost mysql]# tar -zxvf mysql-5.0.51a-linux-i686-glibc23.tar.gz
[root@localhost mysql]# ls
Desktop Download mysql-5.0.51a-linux-i686-glibc23 Pictures Templates
Documents Music mysql-5.0.51a-linux-i686-glibc23.tar.gz Public Videos
4.ÒòΪÓõÄÊÇÔ´´úÂ룬ËùÒÔÒª°ÑÎļþcopyµ½°²×°Ä¿Â¼/usr/local/Ï£¬²ÅÄÜÔËÐÐ!
[root@localhost mysql]# cp -rf mysql-5.0.51a-linux-i686-glibc23 /usr/local/
5.²é¿´ÏµÍ³ÓÐûÓа²×°¹ýmysql,²éÕÒrpm,ÈçÏÂ:
[root@localhost mysql]# rpm -qa | grep mysql
ÓеĻ°Ò»¸öÒ»¸öɾ³ýµô£¬ÓÃrpm -eÃüÁî,È»ºó²éÕÒһϲÐÁôµÄÎļþ:
[root@localhost mysql]# cd /
[root@localhost /]# find / -name mysql
Èç¹û²éÕÒµ½rm -rf filenameɾ³ý.
[root@localhost /]# find / -name my.cnf
Èç¹û²éÕÒµ½É¾³ý£¬Ò»°ãmy.cnfÊÇÔÚ/etc/my.cnfÕâÀï.
6.Á´½Óµ½mysql,ÈçÏ£º
[root@localhost /]# cd /home/mysql
[root@localhost mysql]# ln -s mysql-5.0.51a-linux-i686-glibc23 /usr/local/mysql
7.³õʼ»¯mysql±í¸ñ£¬°²×° mysql ĬÈÏÊý¾Ý¿â£¬ÈçÏ£º
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
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!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
8.ÐÞ¸ÄĿ¼ȨÏÞ£¬ÈçÏ£º
[root@localhost mysql]# cd /usr/local
[root@localhost local]# chgrp -R mysql mysql-5.0.51a-linux-i686-glibc23
[root@localhost local]# chgrp -R mysql mysql
[root@localhost local]# chown -R mysql mysql-5.0.51a-linux-i686-glibc23/data
[root@localhost local]# chown -R mysql mysql/data
[root@localhost local]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
ln: creating symbolic link `/usr/local/bin/CMakeLists.txt': File exists
ln: creating symbolic link `/usr/local/bin/comp_err': File exists
ln: creating symbolic link `/usr/local/bin/comp_sql.c': File exists
ln: creating symbolic link `/usr/local/bin/make_sharedlib_distribution': File exists
ln: creating symbolic link `/usr/local/bin/make_win_bin_dist': File exists
ln: creating symbolic link `/usr/local/bin/make_win_src_distribution_old': File exists
ln: creating symbolic link `/usr/local/bin/msql2mysql': File exists
ln: creating symbolic link `/usr/local/bin/myisamchk': File exists
ln: creating symbolic link `/usr/local/bin/myisam_ftdump': File exists
ln: creating symbolic link `/usr/local/bin/myisamlog': File exists
ln: creating symbolic link `/usr/local/bin/myisampack': File exists
ln: creating symbolic link `/usr/local/bin/my_print_defaults': File exists
ln: creating symbolic link `/usr/local/bin/mysqlaccess': File exists
ln: creating symbolic link `/usr/local/bin/mysqlaccess.conf': File exists
ln: creating symbolic link `/usr/local/bin/mysqladmin': File exists
ln: creating symbolic link `/usr/local/bin/mysqlbinlog': File exists
ln: creating symbolic link `/usr/local/bin/mysqlbug': File exists
ln: creating symbolic link `/usr/local/bin/mysqlcheck': File exists
ln: creating symbolic link `/usr/local/bin/mysql_client_test': File exists
ln: creating symbolic link `/usr/local/bin/mysql_config': File exists
ln: creating symbolic link `/usr/local/bin/mysql_convert_table_format': File exists
ln: creating symbolic link `/usr/local/bin/mysqld': File exists
ln: creating symbolic link `/usr/local/bin/mysqld-debug': File exists
ln: creating symbolic link `/usr/local/bin/mysqld_multi': File exists
ln: creating symbolic link `/usr/local/bin/mysqld_safe': File exists
ln: creating symbolic link `/usr/local/bin/mysqldump': File exists
ln: creating symbolic link `/usr/local/bin/mysqldumpslow': File exists
ln: creating symbolic link `/usr/local/bin/mysql_explain_log': File exists
ln: creating symbolic link `/usr/local/bin/mysql_find_rows': File exists
ln: creating symbolic link `/usr/local/bin/mysql_fix_extensions': File exists
ln: creating symbolic link `/usr/local/bin/mysql_fix_privilege_tables': File exists
ln: creating symbolic link `/usr/local/bin/mysql_fix_privilege_tables_sql.c': File exists
ln: creating symbolic link `/usr/local/bin/mysqlhotcopy': File exists
ln: creating symbolic link `/usr/local/bin/mysqlimport': File exists
ln: creating symbolic link `/usr/local/bin/mysqlmanager': File exists
ln: creating symbolic link `/usr/local/bin/mysql_secure_installation': File exists
ln: creating symbolic link `/usr/local/bin/mysql_setpermission': File exists
ln: creating symbolic link `/usr/local/bin/mysqlshow': File exists
ln: creating symbolic link `/usr/local/bin/mysql_tableinfo': File exists
ln: creating symbolic link `/usr/local/bin/mysqltest': File exists
ln: creating symbolic link `/usr/local/bin/mysqltestmanager': File exists
ln: creating symbolic link `/usr/local/bin/mysqltestmanagerc': File exists
ln: creating symbolic link `/usr/local/bin/mysqltestmanager-pwgen': File exists
ln: creating symbolic link `/usr/local/bin/mysql_tzinfo_to_sql': File exists
ln: creating symbolic link `/usr/local/bin/mysql_upgrade': File exists
ln: creating symbolic link `/usr/local/bin/mysql_upgrade_shell': File exists
ln: creating symbolic link `/usr/local/bin/mysql_waitpid': File exists
ln: creating symbolic link `/usr/local/bin/mysql_zap': File exists
ln: creating symbolic link `/usr/local/bin/ndb_config': File exists
ln: creating symbolic link `/usr/local/bin/ndb_cpcd': File exists
ln: creating symbolic link `/usr/local/bin/ndbd': File exists
ln: creating symbolic link `/usr/local/bin/ndb_delete_all': File exists
ln: creating symbolic link `/usr/local/bin/ndb_desc': File exists
ln: creating symbolic link `/usr/local/bin/ndb_drop_index': File exists
ln: creating symbolic link `/usr/local/bin/ndb_drop_table': File exists
ln: creating symbolic link `/usr/local/bin/ndb_error_reporter': File exists
ln: creating symbolic link `/usr/local/bin/ndb_mgm': File exists
ln: creating symbolic link `/usr/local/bin/ndb_mgmd': File exists
ln: creating symbolic link `/usr/local/bin/ndb_restore': File exists
ln: creating symbolic link `/usr/local/bin/ndb_select_all': File exists
ln: creating symbolic link `/usr/local/bin/ndb_select_count': File exists
ln: creating symbolic link `/usr/local/bin/ndb_show_tables': File exists
ln: creating symbolic link `/usr/local/bin/ndb_size.pl': File exists
ln: creating symbolic link `/usr/local/bin/ndb_test_platform': File exists
ln: creating symbolic link `/usr/local/bin/ndb_waiter': File exists
ln: creating symbolic link `/usr/local/bin/perror': File exists
ln: creating symbolic link `/usr/local/bin/replace': File exists
ln: creating symbolic link `/usr/local/bin/resolveip': File exists
ln: creating symbolic link `/usr/local/bin/resolve_stack_dump': File exists
ln: creating symbolic link `/usr/local/bin/safe_mysqld': File exists
9.Æô¶¯mysql_safe,ÈçÏ£º
[root@localhost local]# bin/mysqld_safe --user=mysql --socket=/tmp/mysql.sock --port=3306 &
[1] 26860
[root@localhost local]# nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /usr/local/mysql/data
²é¿´Ò»Ï 3308 ¶Ë¿ÚÊÇ·ñÒѾ­ÔÚ¼àÌý£º
netstat -anp|grep LISTEN
10.Ìí¼Óµ½ÏµÍ³×ÔÆô¶¯£¬ÈçÏ£º
[root@localhost local]# cp mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost local]# chkconfig --add mysqld
11.Æô¶¯mysql·þÎñ½ø³Ì,ÈçÏ£º
[root@localhost local]# /etc/init.d/mysqld start
Starting MySQL [ OK ]
12.¸ø root Ö¸¶¨ÃÜÂëΪ"python",hostΪlocalhost £¬ÈçÏ£º
[root@localhost local]# bin/mysqladmin --socket=/tmp/mysql.sock --port=3306 -u root -h localhost password 'python'
13.µÇ¼root,²¢¸ørootÊÚȨ!ÈçÏÂËùʾ£º
[root@localhost local]# bin/mysql --port=3306 -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51a MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'python';
Query OK, 0 rows affected (0.54 sec)#[¸øʹÓÃlocalhostÁ¬½ÓµÄrootÓû§ÒÔËùÓÐȨÏÞ]

mysql>flush privileges;
Query OK, 0 rows affected (0.26 sec)#[Ë¢ÐÂÓû§È¨ÏÞÁÐ±í£¬¸üÐÂȨÏÞ]
mysql> quit
Bye
14.н¨Ò»¸öÓû§£¬ÈçÏ£º
//怬MYSQL
[root@localhost local]# bin/mysql --port=3306 -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.51a MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
//ʹÓÃmysqlÊý¾Ý¿â
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
//´´½¨Óû§
mysql> insert into mysql.user(Host,User,Password) values("localhost","django",password("django"));
Query OK, 1 row affected, 3 warnings (0.60 sec)
//Ë¢ÐÂϵͳȨÏÞ±í
mysql> flush privileges;
Query OK, 0 rows affected (0.08 sec)
ÕâÑù¾Í´´½¨ÁËÒ»¸öÃûΪ£ºdjango ÃÜÂëΪ£ºdjango µÄÓû§¡£
//È»ºóµÇ¼һÏÂ
mysql> exit;
Bye
[root@localhost local]# bin/mysql --port=3306 -u django -p -S /tmp/mysql.sock
Enter password: //ÊäÈëÃÜÂë
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.51a MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> //µÇ¼³É¹¦£¡
mysql> exit;
Bye
15.¸øн¨µÄÓû§ÕË»§ÊÚȨ£¬ÈçÏ£º
//µÇ¼MYSQL£¨ÓÐROOTȨÏÞ£©¡£ÎÒÀïÎÒÒÔROOTÉí·ÝµÇ¼.
[root@localhost local]# bin/mysql --port=3306 -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.51a MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
//Ê×ÏÈΪÓû§´´½¨Ò»¸öÊý¾Ý¿â(django_demo)
mysql> create database django_demo;
Query OK, 1 row affected (0.41 sec)
//ÊÚȨdjangoÓû§ÓµÓÐdjango_demoÊý¾Ý¿âµÄËùÓÐȨÏÞ¡£
mysql> grant all privileges on django_demo.* to 'django'@'localhost' identified by 'django';
Query OK, 0 rows affected (0.13 sec)
//Ë¢ÐÂϵͳȨÏÞ±í
mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. linuxfanhhm ÓÚ 2009-06-08 09:18:28·¢±í:

    ²»´í£¬ÓÐûÓгõ¼¶Ò»µãµÄµç×Óµµ£¬ÎÒµÄÓÊÏäÊÇludyhhm@gmail.com