一、卸载旧版本mysql(若无请跳过)
1.使用下面的命令检查是否安装有mysql
rpm -qa|grep -i mysql

2、有的话就卸载

yum remove MySQL-server-5.6.35-1.el6.i686

yum remove MySQL-devel-5.6.35-1.el6.i686

3、删除相关目录

whereis mysql

rm -rf /usr/share/mysql

rm -rf /var/lib/mysql

mv /usr/lib/mysql /usr/lib/mysql.bak #这个当时不确定是rmp包所创建,暂时改名

二、安装MySQL

4、安装编译代码需要的包

yum -y install make gcc-c++ cmake bison-devel ncurses-devel perl perl-devel

5、下载MySQL 5.7.17

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12.tar.gz

tar zxvf mysql-5.7.12.tar.gz

cd mysql-5.7.12

6.递归创建目录:mkdir -p /usr/local/mysql/data

7.下载boost
mysql5.7.17需要这个包来编译,wget网络差会下载失败,可通过浏览器下载后上传
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

解压:
tar zxvf boost_1_59_0.tar.gz

8.编译Mysql:

cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_DATADIR=/usr/local/mysql/data \-DSYSCONFDIR=/etc \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DMYSQL_TCP_PORT=3306 \-DENABLED_LOCAL_INFILE=1 \-DWITH_PARTITION_STORAGE_ENGINE=1 \-DEXTRA_CHARSETS=all \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_BOOST=/home/boost_1_59_0

Centos6源码编译安装Mysql5.7.17教程

编译并且执行:make

检查编译:echo $? 提示0即编译没问题

安装:make install

清除屏幕:make clean

查看是否有用户组:cat /etc/group

创建mysql用户组: groupadd mysql

将用户mysql天添加到MySQL用户组(第一个mysql是用户组):useradd -g mysql mysql

修改mysql的权限: chown -R mysql:mysql /usr/local/mysql

进入mysql安装目录:cd /usr/local/mysql/bin

执行初始化配置脚本,创建系统自带的数据库和表:

./mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

此处会生成一个默认密码,一定要记下来:root@localhost: yfagfl!T&6iq

复制文件:cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

设置为开机自启:chkconfig mysql on

修改默认配置my.cnf:
vi /etc/my.cnf
写入以下内容,这里是最基本的,如果要优化自行优化

[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
lower_case_table_names=1
max_connect_errors=6000
max_connections=1024
query_cache_limit = 2M

启动mysql:service mysql start
(mysql具体启动程序在/etc/rc.d/init.d/mysql,注意有的时候不是mysql,可能是mysqld也可能是mysql)

查看mysql异常日志:安装路径下/usr/local/mysql/data

9、配置用户

设置PATH
vi /etc/profile
在合适位置添加下面一行
PATH=$PATH:/usr/local/mysql/bin
生效:
source /etc/profile
查看:
echo $PATH

10、修改root默认密码
登录mysql:
mysql -uroot -p
输入安装时生成的默认密码回车

修改密码:
mysql> SET PASSWORD = PASSWORD('mysql5635');

刷新权限:
mysql>flush privileges;

设置mydba用户可以远程访问

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql5635' WITH GRANT OPTION;

防火墙设置可参考 http://www.cnblogs.com/ShanFish/p/6519950.html

防火墙关闭: /etc/sysconfig/iptables stop

防火墙配置: vi /etc/sysconfig/iptables

加入

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

12、补充

退出后重新在终端登录

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

bash: mysql: command not found

使用完整的路径可以登录

[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p
(mysql登录的完整的路径在/usr/local/mysql/bin/mysql -uroot -p)

Enter password:

最后建立一个软链接,其它常用命令mysqladmin、mysqldump等不可用时候都可按用此方法解决

[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin

直接运行export命令定义变量【只对当前shell有效(临时的)】

[root@VMUest ~]# export PATH=/usr/local/mysql/bin:$PATH

[root@VMUest ~]# echo $PATH

它只对当前的shell有效,因此刚配置时可以使用mysql,退出登录就不能使用。后来将export写入到文件/etc/profile,就可以永久有

naicat远程本地错误解决10061分析;

1.可能是防火墙没开

2.在etc找到my.cnf添加bind-address=0.0.0.0(windows是my.ini)

3在mysql设置权限:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql5635' WITH GRANT OPTION;

参考文章:
https://www.cnblogs.com/AllenJol/p/6609929.html
https://blog.csdn.net/embracejava/article/details/53996794
https://blog.csdn.net/weixin_37750188/article/details/78816712