系统版本: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/文件夹下。
- sudo tar zcvf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz /usr/local/mysql-5.6.14/
解压后的文件目录:
2、创建用户和组。
创建组:
- sudo groupadd mysql
创建用户:
- sudo useradd -r -g mysql mysql
在此创建的mysql用户只是用来控制文件的权限,可以使用“-r”参数,让该用户不需要登录。
3、改变/usr/local/mysql-5.6.14/文件夹的所有者为mysql用户。
- sudo chown -R mysql:mysql /usr/local/mysql-5.6.14/
4、 安装共享库libaio1。
- sudo apt-get install libaio1
5、 使用mysql_install_db初始化授权表。
- sudo scripts/mysql_install_db --user=mysql
6、配置mysql服务。
打开/etc/init.d/文件夹:
- cd /etc/init.d
创建mysql服务的链接:
- sudo ln -s /usr/local/mysql-5.6.14/support-files/mysql.server
打开/usr/local/文件夹:
- cd /usr/local
创建mysql的链接:
- sudo ln -s /usr/local/mysql-5.6.14 mysql
- sudo chown -R mysql:mysql mysql
- sudo /etc/init.d/mysql.server start
- ps -aux | grep mysql
![点击查看原始大小图片](https://i-blog.csdnimg.cn/blog_migrate/237c603cccda5112e3ead052fd81ec9f.png)
8、查看mysql版本;
- bin/mysqladmin version
![点击查看原始大小图片](https://i-blog.csdnimg.cn/blog_migrate/9ed1bbc0b2bf694020d17411462dab95.png)
mysql安装成功。
下面开始配置mysql:
1、为mysql的root用户创建密码。
首先。进入mysql的安装目录(mysql默认安装到/usr/local/mysql文件夹下):
- cd /usr/local/mysql
- ./bin/mysqladmin -u root password '123456'
2、安全配置,删除Test数据库和匿名操作等。
输入以下代码:
- sudo bin/mysql_secure_installation
- NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
- SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
- In order to log into MySQL to secure it, we'll need the current
- password for the root user. If you've just installed MySQL, and
- you haven't set the root password yet, the password will be blank,
- so you should just press enter here.
- Enter current password for root (enter for none):
- OK, successfully used password, moving on...
- Setting the root password ensures that nobody can log into the MySQL
- root user without the proper authorisation.
- You already have a root password set, so you can safely answer 'n'.
- Change the root password? [Y/n] n
- ... skipping.
- By default, a MySQL installation has an anonymous user, allowing anyone
- to log into MySQL without having to have a user account created for
- them. This is intended only for testing, and to make the installation
- go a bit smoother. You should remove them before moving into a
- production environment.
- Remove anonymous users? [Y/n] y
- ... Success!
- Normally, root should only be allowed to connect from 'localhost'. This
- ensures that someone cannot guess at the root password from the network.
- Disallow root login remotely? [Y/n] y
- ... Success!
- By default, MySQL comes with a database named 'test' that anyone can
- access. This is also intended only for testing, and should be removed
- before moving into a production environment.
- Remove test database and access to it? [Y/n] y
- - Dropping test database...
- ... Success!
- - Removing privileges on test database...
- ... Success!
- Reloading the privilege tables will ensure that all changes made so far
- will take effect immediately.
- Reload privilege tables now? [Y/n] y
- ... Success!
- All done! If you've completed all of the above steps, your MySQL
- installation should now be secure.
- Thanks for using MySQL!
- Cleaning up...
3、配置开机启动。
- sudo update-rc.d mysql.server defaults
4、环境变量配置。
由于使用二进制安装mysql,系统对在终端下直接输入mysql等命令不能识别,每次执行mysql命令都要输入绝对路径或者必须在安装目录下执行,比较麻烦,因此,可以采用配置环境变量的方式来解决。
编辑/etc/profile文件:
- sudo getdit /etc/profile
将下面的代码加入/etc/profile文件中。
- export PATH="$PATH:/usr/local/mysql/bin"
![点击查看原始大小图片](https://i-blog.csdnimg.cn/blog_migrate/28e3c10d5ea0fcddecb3434e9a7cc33d.png)
环境变量配置完成。