linux下安装mysql

// 查询出来已安装的mariadb

[root@localhost ~]# rpm -qa|grep mariadb

// 卸载mariadb,文件名为上述命令查询出来的文件

[root@localhost ~]# rpm -e --nodeps 文件名

//删除etc目录下的my.cnf

[root@localhost ~]# rm /etc/my.cnf

//执行以下命令来创建mysql用户组

[root@localhost ~]# groupadd mysql

//执行以下命令来创建一个用户名为mysql的用户并加入mysql用户组

[root@localhost ~]# useradd -g mysql mysql

// 进入/usr/local/下,解压安装包

[root@localhost local]# tar -xvf mysql-5.6.34-linux-glibc2.5-x86_64.tar

// 重命名文件 /usr/local

[root@localhost local]# mv mysql-5.6.34-linux-glibc2.5-x86_64 mysql

// 在 etc 下新建配置文件my.cnf 文件路径 /usr/local/mysql/support-files

[root@localhost support-files]# cp my-default.cnf /etc/my.cnf

// 编辑my.cnf文件,参考文件内容在最后面

[root@localhost support-files]# vim /etc/my.cnf

// 进入目录

[root@localhost ~]# cd /usr/local/mysql

//修改当前目录拥有着为mysql用户

[root@localhost mysql]# chown -R mysql:mysql ./

//创建文件夹 这个目录在my.cnf有用到

[root@localhost mysql]# mkdir  /var/lib/mysql/

//给权限

[root@localhost mysql]# chown -R mysql:mysql ./

// 安装数据库

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

// 修改当前data目录的拥有者为mysql用户

[root@localhost mysql]# chown -R mysql:mysql data

// 授予my.cnf最大权限

[root@localhost ~]# chown 777 /etc/my.cnf

// 设置开机自启动服务控制脚本:

// 复制启动脚本到资源目录

[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

// 增加mysqld服务控制脚本执行权限

[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld

// 将mysqld服务加入到系统服务

[root@localhost mysql]# chkconfig --add mysqld

// 检查mysqld服务是否已经生效

[root@localhost mysql]# chkconfig --list mysqld

// 命令输出类似下面的结果:

// mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

// 表明mysqld服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制mysql的启动和停止

//命令为:service mysqld start和service mysqld stop

// 启动mysqld

[root@localhost mysql]# service mysqld start

// 将mysql的bin目录加入PATH环境变量,编辑 ~/.bash_profile文件

[root@localhost mysql]# vim ~/.bash_profile

//在文件最后添加如下信息:

export PATH=$PATH:/usr/local/mysql/bin

// 执行下面的命令是修改的内容立即生效:

[root@localhost mysql]# source ~/.bash_profile

// 以root账户登录mysql,默认是没有密码的

[root@localhost mysql]# mysql -uroot -p

// 要输入密码的时候直接回车即可。

// 设置root账户密码为root(也可以修改成你要的密码)

mysql>use mysql

//需要远程连接的话将localhost换成%

mysql>update user set password=password('root') where user='root' and host='localhost';

mysql>flush privileges;

// 中间报错缺少东西,可尝试执行

yum -y install autoconf


my.cnf文件参考内容   请仔细核对路径

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# socket = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

socket=/var/lib/mysql/mysql.sock

[mysqld]

skip-name-resolve

#设置3306端口

port = 3306

socket=/var/lib/mysql/mysql.sock

# 设置mysql的安装目录

basedir=/usr/local/mysql

# 设置mysql数据库的数据的存放目录

datadir=/usr/local/mysql/data

# 允许最大连接数

max_connections=200

# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

lower_case_table_name=1

max_allowed_packet=16M

你可能感兴趣的:(linux下安装mysql)