ubuntu 12.04安装mysql 5.6.14

来源:互联网 发布:房地产数据供应商 编辑:程序博客网 时间:2024/05/04 23:02

系统版本:Ubuntu 12.04 LTS 64位

mysql版本:mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz

 

 1、将下载的mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz解压到/usr/local/mysql-5.6.14/文件夹下。

Java代码  收藏代码
  1. sudo tar zcvf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz /usr/local/mysql-5.6.14/  

 

 解压后的文件目录:



 

 2、创建用户和组。

 创建组:

Java代码  收藏代码
  1. sudo groupadd mysql  

 

 创建用户:

Java代码  收藏代码
  1. sudo useradd -r -g mysql mysql  

 

 在此创建的mysql用户只是用来控制文件的权限,可以使用“-r”参数,让该用户不需要登录。

 

 3、改变/usr/local/mysql-5.6.14/文件夹的所有者为mysql用户。

 

Java代码  收藏代码
  1. sudo chown -R mysql:mysql /usr/local/mysql-5.6.14/  

 

 

 4、 安装共享库libaio1

 

Java代码  收藏代码
  1. sudo apt-get install libaio1  
 

 

 5、 使用mysql_install_db初始化授权表。

Java代码  收藏代码
  1. sudo scripts/mysql_install_db --user=mysql  
 

 

 6、配置mysql服务。

 打开/etc/init.d/文件夹:

Java代码  收藏代码
  1. cd /etc/init.d  
 

 创建mysql服务的链接:

Java代码  收藏代码
  1. sudo ln -s /usr/local/mysql-5.6.14/support-files/mysql.server  
 

 打开/usr/local/文件夹:

Java代码  收藏代码
  1. cd /usr/local  
  
 创建mysql的链接:
Java代码  收藏代码
  1. sudo ln -s /usr/local/mysql-5.6.14 mysql  
 把mysql服务的所有权赋予mysql用户:
Java代码  收藏代码
  1. sudo chown -R mysql:mysql mysql  
 启动mysql:
Java代码  收藏代码
  1. sudo /etc/init.d/mysql.server start   
 7、查看进程,看mysql服务是否启动。
Java代码  收藏代码
  1. ps -aux | grep mysql  
 

 
 8、查看mysql版本;
Java代码  收藏代码
  1. bin/mysqladmin version  
 
 mysql安装成功。
 下面开始配置mysql:
 1、为mysql的root用户创建密码。
 首先。进入mysql的安装目录(mysql默认安装到/usr/local/mysql文件夹下):
Java代码  收藏代码
  1. cd /usr/local/mysql  
  其次,输入以下代码,设置新密码:
Java代码  收藏代码
  1. ./bin/mysqladmin -u root password '123456'  
 
 2、安全配置,删除Test数据库和匿名操作等。
 输入以下代码:
Java代码  收藏代码
  1. sudo bin/mysql_secure_installation  
 接下来,只要按照提示进行操作就可以了:
Java代码  收藏代码
  1. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  
  2.       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!  
  3.   
  4. In order to log into MySQL to secure it, we'll need the current  
  5. password for the root user.  If you've just installed MySQL, and  
  6. you haven't set the root password yet, the password will be blank,  
  7. so you should just press enter here.  
  8.   
  9. Enter current password for root (enter for none):   
  10. OK, successfully used password, moving on...  
  11.   
  12. Setting the root password ensures that nobody can log into the MySQL  
  13. root user without the proper authorisation.  
  14.   
  15. You already have a root password set, so you can safely answer 'n'.  
  16.   
  17. Change the root password? [Y/n] n  
  18.  ... skipping.  
  19.   
  20. By default, a MySQL installation has an anonymous user, allowing anyone  
  21. to log into MySQL without having to have a user account created for  
  22. them.  This is intended only for testing, and to make the installation  
  23. go a bit smoother.  You should remove them before moving into a  
  24. production environment.  
  25.   
  26. Remove anonymous users? [Y/n] y  
  27.  ... Success!  
  28.   
  29. Normally, root should only be allowed to connect from 'localhost'.  This  
  30. ensures that someone cannot guess at the root password from the network.  
  31.   
  32. Disallow root login remotely? [Y/n] y  
  33.  ... Success!  
  34.   
  35. By default, MySQL comes with a database named 'test' that anyone can  
  36. access.  This is also intended only for testing, and should be removed  
  37. before moving into a production environment.  
  38.   
  39. Remove test database and access to it? [Y/n] y  
  40.  - Dropping test database...  
  41.  ... Success!  
  42.  - Removing privileges on test database...  
  43.  ... Success!  
  44.   
  45. Reloading the privilege tables will ensure that all changes made so far  
  46. will take effect immediately.  
  47.   
  48. Reload privilege tables now? [Y/n] y  
  49.  ... Success!  
  50.   
  51.   
  52.   
  53.   
  54. All done!  If you've completed all of the above steps, your MySQL  
  55. installation should now be secure.  
  56.   
  57. Thanks for using MySQL!  
  58.   
  59.   
  60. Cleaning up...  
 3、配置开机启动。
 
Java代码  收藏代码
  1. sudo update-rc.d mysql.server defaults  
 
 4、环境变量配置。
 由于使用二进制安装mysql,系统对在终端下直接输入mysql等命令不能识别,每次执行mysql命令都要输入绝对路径或者必须在安装目录下执行,比较麻烦,因此,可以采用配置环境变量的方式来解决。
 编辑/etc/profile文件:
Java代码  收藏代码
  1. sudo getdit /etc/profile  
 
 将下面的代码加入/etc/profile文件中。
Java代码  收藏代码
  1. export PATH="$PATH:/usr/local/mysql/bin"  
  保存,重启电脑。mysql命令就可以在终端下直接使用了。
 

 
 环境变量配置完成。
原创粉丝点击