赞
踩
//检查系统中有无安装过mysql
rpm -qa|grep mysql
//查询所有mysql 对应的文件夹,全部删除
whereis mysql
find / -name mysql
# 查看系统自带的Mariadb
[root@cVzhanshi ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
# 卸载系统自带的Mariadb
[root@cVzhanshi ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
# 删除etc目录下的my.cnf ,一定要删掉,等下再重新建,之前我将就用这个文件,后面改配置各种不生效
[root@cVzhanshi ~]# rm /etc/my.cnf
//检查mysql 用户组是否存在
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
// 创建mysql 用户组和用户
groupadd mysql
useradd -r -g mysql mysql
下载安装,从官网安装下载,我下载的位置在/usr/local/
下载地址
tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql # 顺便改一下名字
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
vi /etc/my.cnf
文件内容
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1
#查询服务
ps -ef|grep mysql
ps -ef|grep mysqld
#结束进程
kill -9 PID
#启动服务
/usr/local/mysql/support-files/mysql.server start
//添加软连接
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
//重启mysql服务
service mysql restart
mysql -u root -p # 密码是之前生成的临时密码
注意: 分号(;) 结尾
set password for root@localhost = password('123456');
开放远程连接
use mysql;
update user set user.Host='%' where user.User='root';
flush privileges;
设置开机自启
//将服务文件拷贝到init.d下,并重命名为mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
//赋予可执行权限
chmod +x /etc/init.d/mysqld
//添加服务
chkconfig --add mysqld
//显示服务列表
chkconfig --list
//检查系统中有无安装过mysql
rpm -qa|grep mysql
//查询所有mysql 对应的文件夹,全部删除
whereis mysql
find / -name mysql
# 查看系统自带的Mariadb
[root@cVzhanshi ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
# 卸载系统自带的Mariadb
[root@cVzhanshi ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
# 删除etc目录下的my.cnf ,一定要删掉,等下再重新建,之前我将就用这个文件,后面改配置各种不生效
[root@cVzhanshi ~]# rm /etc/my.cnf
把客户端和服务端下载好传到Linux中
[root@cVzhanshi opt]# rpm -ivh MySQL-server-5.5.48-1.linux2.6.i386.rpm
要是报错:
解决方案:
[root@cVzhanshi opt]# yum -y install libaio.so.1
[root@cVzhanshi opt]# yum -y install libm.so.6
[root@cVzhanshi opt]# rpm -ivh MySQL-client-5.5.48-1.linux2.6.i386.rpm
同理报错:
解决方案:
[root@cVzhanshi opt]# yum -y install libncurses.so.5
[root@cVzhanshi opt]# cat /etc/passwd|grep mysql
mysql:x:987:980:MySQL server:/var/lib/mysql:/bin/bash
[root@cVzhanshi opt]# cat /etc/group|grep mysql
mysql:x:980:
[root@cVzhanshi opt]# mysqladmin --version
mysqladmin Ver 8.42 Distrib 5.5.48, for Linux on i686
[root@cVzhanshi opt]# service mysql start
如果出现一下错误:
解决方案:
# 执行以下命令
[root@cVzhanshi mysql]# /usr/bin/mysql_install_db --user=mysql
[root@cVzhanshi mysql]# service mysql start
Starting MySQL.. SUCCESS!
此时mysql是没有密码的,输入mysql就能进入mysql
[root@cVzhanshi mysql]# /usr/bin/mysqladmin -u root password 123456
# 尝试进入mysql 发现报错
[root@cVzhanshi mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@cVzhanshi mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.48 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
[root@cVzhanshi mysql]# chkconfig mysql on
# 查看是否开启
[root@cVzhanshi opt]# ntsysv
查看状态
新安装mysql字符集没有统一,可能会出现乱码问题
查看字符集
# 先cp配置文件到etc路径下
[root@cVzhanshi mysql]# cp my-huge.cnf /etc/my.cnf
# 编写配置文件
[root@cVzhanshi etc]# vim my.cnf
# 增加的修改内容如下:
[client]
default-character-set=utf8
[mysqld]
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
[mysql]
default-character-set=utf8
重启服务
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。