1 安装前执行以下命令,删除以前配置
rm -rf /etc/my.cnf
rm -rf /etc/init.d/mysqld
2 安装前执行以下命令,检查mysql依赖库是否存在,没有就安装
yum search libaio
yum install libaio
3 下载mysql5.6到 linux /packages 目录下面
need-to-insert-img
下载链接 :https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
4 创建mysql与用户组,-s /bin/false标识该用户不能登录
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
5 解压mysql到 /usr/mysql
mkdir /usr/mysql
cd /packages
tar -zxvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz -C /usr/mysql/
6 进入mysql目录,并创建一个软链接 ,进入软连接
cd /usr/mysql/mysql-5.6.38-linux-glibc2.12-x86_64
ln -s /usr/mysql/mysql-5.6.38-linux-glibc2.12-x86_64/ mysql
cd mysql
7 为mysql用户添加权限
chown -R mysql ./
chgrp -R mysql ./
8 在根目录添加data目录,并添加权限
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
9 拷贝配置文件
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysql
10 初始化mysql数据库
vi /etc/init.d/mysql
配置下面两个
basedir=/usr/mysql/mysql-5.6.38-linux-glibc2.12-x86_64/mysql
datadir=/data/mysql
保存并退出,执行下面
./scripts/mysql_install_db --user=mysql --basedir=/usr/mysql/mysql-5.6.38-linux-glibc2.12-x86_64/mysql --datadir=/data/mysql
11 添加环境变量
vi /etc/profile
#set mysql pathmunge
#PATH=/usr/mysql/mysql-5.6.38-linux-glibc2.12-x86_64/mysql/bin:$PATH
export PATH=/usr/mysql/mysql-5.6.38-linux-glibc2.12-x86_64/mysql/bin:$PATH
保存退出
让刚才修改生效
source /etc/profile
12 启动数据库
service mysql start
13 开机启动
chkconfig mysql on
14 初始化设置,如果此处报错commond not found 查一下是不是PATH配置错误。
mysql_secure_installation
回车
出现如下
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.
Set root password? [Y/n]
直接输入y,回车,设置新的root用户密码
设置两次完成后,出现如下
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]
这是提示删除安装时的mysql匿名用户,此时直接输入y,回车,然后出现如下
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]
提示是否设置禁止远程登录root用户,输入y回车 ,然后出现如下
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]
这是提示mysql自带一个test的测试数据库,是否删除,直接输入y回车,然后出现如下
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
这是提示是否当前所有设置立即生效,直接输入y,回车,出现如下,表示完成!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
15 创建远程用户
mysql -u root -p
然后输入密码 ,进入mysql
切换数据库
use mysql
创建用户blues,密码为123456,可以在任意远程登录
CREATE USER 'blues'@'%' IDENTIFIED BY '123456';
授权给用户
GRANT ALL ON *.* TO 'blues'@'%';
刷新mysql系统用户权限
flush privileges;
注意:如果远程连接不上,有可能是服务器3306端口防火墙没有开放,执行以下命令
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
此时远程Navicat可以连接刚刚安装的数据库了。
作者:郭艺宾
链接:https://www.jianshu.com/p/e6bfe6afb16a
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。