在Linux下安装MySQL的二进制源代码包
这几天研究了好久,终于被我知道了如何在Linux下安装mysql的二进制源代码包,最终解决了ERROR 1045 (28000): Access denied for
这几天研究了好久,终于被我知道了如何在Linux下安装mysql的二进制源代码包,最终解决了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的权限问题,真的是感慨万分啊,只想把他写出来,让自己以后不要忘记了,,好了,废话不多说了,看看我的安装步骤吧!
1.下载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
Support MySQL by buying support/licenses at
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)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.
