linux系统安装mysql

linux版本:

    1、下载安装包“mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz”   

wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz 
# 安装依赖
yum -y install perl perl-devel autoconf libaio

    2、把下载的安装包移动到/usr/local/下。

    3、解压

tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

    4、复制解压后的mysql目录到系统的本地软件目录

cp mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql -r

    5、添加系统mysql组和mysql用户

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
注意:Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them.

    6、进入安装mysql软件目录,修改目录拥有者为mysql用户

cd mysql/
chown -R mysql:mysql ./

    7、安装数据库,此处可能出现错误。

./scripts/mysql_install_db --user=mysql
问题1:FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
    Data::Dumper

#解决方法:
yum install -y perl-Data-Dumper

问题2:Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared   原因是:缺少libaio库文件
#解决方法:
yum install libaio* -y

    8、修改当前目录拥有者为root用户

chown -R root:root ./

    9、修改当前data目录拥有者为mysql用户

chown -R mysql:mysql data

============== 到此数据库安装完毕 =============

    10、添加mysql服务开机自启动

添加开机启动,把启动脚本放到开机初始化目录。

复制代码
cp support-files/mysql.server /etc/init.d/mysql
# 赋予可执行权限
chmod +x /etc/init.d/mysql
# 添加服务
chkconfig --add mysql 
# 显示服务列表
chkconfig --list 
复制代码

如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则执行

chkconfig --level 345 mysql on

    11、启动mysql服务

#创建缺少的文件夹
mkdir /var/log/mariadb
service mysql start

正常提示信息:Starting MySQL. SUCCESS!

12、把mysql客户端放到默认路径

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

通过使用 mysql -uroot -p 连接数据库(默认数据库的root用户没有密码,这个需要设置一个密码)。

 

----------------------创建自己的用户------------------------------------

添加新用户

允许本地 IP 访问 localhost, 127.0.0.1

create user 'test'@'localhost' identified by '123456';
允许外网 IP 访问

create user 'test'@'%' identified by '123456';
刷新授权
flush privileges;
为用户创建数据库
create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
为新用户分配权限
授予用户通过外网IP对于该数据库的全部权限

grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';
授予用户在本地服务器对该数据库的全部权限
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';
刷新权限
flush privileges;
退出 root 重新登录
exit
用新帐号 test 重新登录,由于使用的是 % 任意IP连接,所以需要指定外部访问IP
mysql -u test -h 115.28.203.224 -p

------------------在mysql -uroot -p下创建user的另一方法-----------------------------------------

GRANT USAGE ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'admin' WITH GRANT OPTION; 

 

------------------出现中文乱码问题的解决-----------------------------------------

https://blog.csdn.net/sayoko06/article/details/76679380

https://www.cnblogs.com/jasonzeng/p/8341445.html

posted on 2018-11-24 12:13  心静无痕  阅读(212)  评论(0编辑  收藏  举报