Ubuntu 13.04中源码方式安装MySQL 5.5.33

来源:互联网 发布:金融 知乎 编辑:程序博客网 时间:2024/06/07 01:07


转载:http://lssrc.com/archives/385

环境:Ubuntu 13.04

数据库:MySQL 5.5.33

1.下载MySQL 5.5.33源码,地址http://dev.mysql.com/downloads/mysql/5.5.html#downloads

mysqlsourcecode-lssrc

mysqltargz-lssrc

2.删除已安装过的MySQL

  1. carl@Carl-U:~$ sudo apt-get remove mysql*  

3.添加用户组和用户

  1. carl@Carl-U:~$ sudo groupadd mysql   
  2. carl@Carl-U:~$ sudo useradd -r -g mysql mysql  

4.创建MySQL的安装目录

  1. carl@Carl-U:~$ sudo mkdir /usr/local/mysql  

5.修改MySQL安装目录所有者

  1. carl@Carl-U:~$ sudo chown mysql:mysql /usr/local/mysql/  

6.解压源码包

  1. carl@Carl-U:~$ sudo tar -zxvf mysql-5.5.33.tar.gz  

7.进入 mysql-5.5.33目录内,因为在新版本的MySQL源码包中没有了configure,改用cmake方式编译。如果没有安装,先安装cmake

  1. carl@Carl-U:~$ sudo apt-get install cmake   
  2. carl@Carl-U:~$ sudo apt-get install libncurses5-dev  

注:ubuntu下安装libncurses5-dev;redhat下安装ncurses-devel
还需要其他程序

  1. carl@Carl-U:~$ sudo apt-get install g++   
  2. carl@Carl-U:~$ sudo apt-get install bison   
  3. carl@Carl-U:~$ sudo apt-get install libaio1  

8.编译

  1. carl@Carl-U:~$ sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    
  2. -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock    
  3. -DDEFAULT_CHARSET=utf8    
  4. -DDEFAULT_COLLATION=utf8_general_ci    
  5. -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk    
  6. -DWITH_MYISAM_STORAGE_ENGINE=1    
  7. -DWITH_INNOBASE_STORAGE_ENGINE=1    
  8. -DWITH_MEMORY_STORAGE_ENGINE=1    
  9. -DWITH_READLINE=1    
  10. -DENABLED_LOCAL_INFILE=1    
  11. -DMYSQL_DATADIR=/usr/local/mysql/data    
  12. -DMYSQL_USER=mysql    
  13. -DMYSQL_TCP_PORT=3306  

编译结束后,出现下面的警告,不妨碍执行make

  1. ……   
  2. – Generating done   
  3.   
  4. CMake Warning:   
  5.   
  6.   Manually-specified variables were not used by the project:   
  7.   
  8.     MYSQL_USER   
  9.   
  10.     WITH_MEMORY_STORAGE_ENGINE   
  11.   
  12. – Build files have been written to: /home/carl/mysql-5.5.33  

9.执行make和make install

  1. carl@Carl-U:~/mysql-5.5.33$ sudo make   
  2.   
  3. – Running cmake version 2.8.10.1   
  4.   
  5. – Looking for SHM_HUGETLB   
  6.   
  7. – Looking for SHM_HUGETLB - found   
  8.   
  9. – MySQL 5.5.33   
  10.   
  11. – Looking for sys/types.h   
  12.   
  13. – Looking for sys/types.h - found   
  14.   
  15. – Looking for stdint.h   
  16.   
  17. ……  
  1. carl@Carl-U:~/mysql-5.5.33$ sudo make install   
  2.     
  3. [  0%] Built target INFO_BIN   
  4.   
  5. [  0%] Built target INFO_SRC   
  6.   
  7. [  0%] Built target abi_check   
  8.   
  9. [  2%] Built target zlib   
  10. ……  

10.从源码目录拷贝一些配置文件

  1. carl@Carl-U:~$ cd /home/carl/mysql-5.5.33/support-files/    
  2. carl@Carl-U:~/mysql-5.5.33/support-files$ sudo cp my-medium.cnf /etc/my.cnf   
  3. carl@Carl-U:~/mysql-5.5.33/support-files$ sudo cp mysql.server /etc/init.d/mysql  

还要给/etc/init.d/mysql一个可执行的权限

  1. carl@Carl-U:~/mysql-5.5.33/support-files$ sudo chmod +x /etc/init.d/mysql  

修改一下这个文件

  1. carl@Carl-U:~/mysql-5.5.33/support-files$ sudo vi /etc/init.d/mysql     
  2. //修改内容   
  3. basedir=/usr/local/mysql/    
  4. datadir=/usr/local/mysql/data/  

11.初始化数据库
进入MySQL安装后的目录

  1. carl@Carl-U:~/mysql-5.5.33$ cd /usr/local/mysql/   
  2. carl@Carl-U:/usr/local/mysql$ sudo scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql/ –datadir=/usr/local/mysql/data  

出现以下提示

  1. Installing MySQL system tables…    
  2. OK    
  3. Filling help tables…    
  4. OK    
  5.     
  6. To start mysqld at boot time you have to copy    
  7. support-files/mysql.server to the right place for your system    
  8.     
  9. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !    
  10. To do so, start the server, then issue the following commands:    
  11.     
  12. /usr/local/mysql//bin/mysqladmin -u root password ’new-password’    
  13. /usr/local/mysql//bin/mysqladmin -u root -h Carl-U password ’new-password’    
  14.     
  15. Alternatively you can run:    
  16. /usr/local/mysql//bin/mysql_secure_installation    
  17.     
  18. which will also give you the option of removing the test    
  19. databases and anonymous user created by default.  This is    
  20. strongly recommended for production servers.    
  21.     
  22. See the manual for more instructions.    
  23.     
  24. You can start the MySQL daemon with:    
  25. cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &    
  26.     
  27. You can test the MySQL daemon with mysql-test-run.pl    
  28. cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl    
  29.     
  30. Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!   

12.启动MySQL服务

  1. carl@Carl-U:/usr/local/mysql$ sudo /etc/init.d/mysql start    
  2. Starting MySQL    
  3. ….. *   

13.修改数据库root用户的密码

  1. carl@Carl-U:~$ sudo /usr/local/mysql/bin/mysqladmin -u root password ’root’  

13.登录
这时候直接输入mysql是找不到的
需要使用/usr/local/mysql/bin/mysql

  1. carl@Carl-U:~$ sudo /usr/local/mysql/bin/mysql -u root -p    
  2. Enter password:     
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.    
  4. Your MySQL connection id is 2    
  5. Server version: 5.5.33-log Source distribution    
  6.     
  7. Copyright (c) 20002013, Oracle and/or its affiliates. All rights reserved.    
  8.     
  9. Oracle is a registered trademark of Oracle Corporation and/or its    
  10. affiliates. Other names may be trademarks of their respective    
  11. owners.    
  12.     
  13. Type ’help;’ or ’\h’ for help. Type ’\c’ to clear the current input statement.    
  14.     
  15. mysql>  

查看有哪些数据库

  1. mysql> show databases;    
  2. +———————-+    
  3. Database             |    
  4. +———————-+    
  5. | information_schema   |    
  6. | mysql                |    
  7. | performance_schema   |    
  8. | test                 |    
  9. +———————-+    
  10. rows in set (0.00 sec)   

查看有哪些mysql用户

  1. mysql> use mysql;   
  2. mysql> select user,host,password from user;    
  3. +——+————+——————————————-+    
  4. user | host       | password                                  |    
  5. +——+————+——————————————-+    
  6. | root | localhost  | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |    
  7. | root | Carl-U     |                                           |    
  8. | root | 127.0.0.1  |                                           |    
  9. | root | ::1        |                                           |    
  10. |      | localhost  |                                           |    
  11. |      | Carl-U     |                                           |    
  12. +——+————+——————————————-+    
  13. rows in set (0.00 sec)  

删除密码为空的用户

  1. mysql> delete from user where password=;    
  2. Query OK, 5 rows affected (0.00 sec)  

14.创建一个可以远程链接的用户

  1. mysql> grant all privileges on *.* to root@’%' identified by ’root’ with grant option;    
  2. mysql> flush privileges;  

15.创建一个链接

  1. carl@Carl-U:~$ sudo ln -s /usr/local/mysql/bin/mysql /usr/bin/  

这时候使用mysql不会提示找不到了

  1. carl@Carl-U:~$ mysql -u root -p    
  2. Enter password:     
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.    
  4. Your MySQL connection id is 10    
  5. Server version: 5.5.33-log Source distribution    
  6.     
  7. Copyright (c) 20002013, Oracle and/or its affiliates. All rights reserved.    
  8.     
  9. Oracle is a registered trademark of Oracle Corporation and/or its    
  10. affiliates. Other names may be trademarks of their respective    
  11. owners.    
  12.     
  13. Type ’help;’ or ’\h’ for help. Type ’\c’ to clear the current input statement.    
  14.     
  15. mysql>  

16.安装过程中有问题请了留言。

原创粉丝点击