liunx 下mysql 的安装

参考地址
http://blog.csdn.net/wendi_0506/article/details/39478369
https://www.chenyudong.com/archives/building-mysql-5-6-from-source.html
http://blog.csdn.net/wendi_0506/article/details/39478369
  1. 查看当前系统是否安装mysql
[root@localhost mysql]#  rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@localhost mysql]# rpm -e mysql-libs-5.1.71-1.el6.x86_64
error: Failed dependencies:
libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
mysql-libs is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
存在依赖关系,直接删除
[root@localhost mysql]# rpm -e --nodeps  mysql-libs-5.1.71-1.el6.x86_64
[root@localhost mysql]# rpm -qa |grep mysql
没有mysql 即可
  1. 安装mysql 所需要的一些必要的库 yum install gcc gcc-c++ ncurses-devel perl
  1. 安装cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz   
或者到 
http://note.youdao.com/yws/public/redirect/share?id=ad618b9375cbe1a115edaba83af58390&type=false
下载
可能会出现以下错误:
Connecting to cmake.org|66.194.253.19|:443... connected.
ERROR: certificate common name “*.kitware.com” doesn’t match requested host name “cmake.org”.
To connect to cmake.org insecurely, use ‘--no-check-certificate’.
只需要:
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz --no-check-certificate
tar -xzvf cmake-2.8.10.2.tar.gz   
cd cmake-2.8.10.2   
./bootstrap ; make ; make install
查看是否成功
cmake--version
  1. 用户用户组及目录的创建
groupadd mysql 
useradd -r -g mysql mysql
  1. 解压 mysql 源码包
tar -zxv -f mysql-5.6.16.tar.gz  
cd mysql-5.6.16
  1. cmake 安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/soft/mysql-5.6.29/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/data/mysqldb \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1 
在cmake的时候出现
[root@localhost mysql-5.6.29]# cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \   
CMake Error: The source directory "/usr/local/soft/mysql-5.6.29/ " does not exist.
原因:
在 "\" 后面有空格
  1. cmake 出现以下输出说明cmake成功
-- Running cmake version 2.6.4
-- MySQL 5.6.16
-- Packaging as: mysql-5.6.16-Linux-x86_64
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- HAVE_VISIBILITY_HIDDEN
-- Using cmake version 2.6.4
-- Not building NDB
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- GMOCK_SOURCE_DIR:/root/mysql-5.6.16/source_downloads/gmock-1.6.0
-- GTEST_LIBRARIES:gmock;gtest
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mysql-5.6.16
  1. 编译源码
make && make install
  1. 复制配置文件
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld
  1. 初始化数据库
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb/
出现以下信息说明已经初始化成功
New default config file was created as /usr/local/mysql//my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
  1. 启动mysql
/etc/init.d/mysqld start
遇到以下问题:
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL... ERROR! The server quit without updating PID file (/data/mysqldb/localhost.localdomain.pid).
1、可能是/usr/local/mysql/data/mysql.pid文件没有写的权限
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data”
“chmod -R 755 /usr/local/mysql/data”  然后重新启动mysqld!
2、可能进程里已经存在mysql进程
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程
,如果有使用“kill -9  进程号”杀死,然后重新启动mysqld!
3、更多原因请查看:http://www.jb51.net/article/48625.htm
启动完成之后用ps -ef |grep mysql 命令查看是否启动
  1. 修改root密码
root 的初始密码为空,登入修改root账户的密码
[root@localhost mysql]# /usr/local/mysql/bin/mysql -u root -p
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=PASSWORD("123456") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
退出
[root@localhost bin]# /usr/local/mysql/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.29 Source distribution
登入成功可以操作数据库了
#问题  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
#1.停止mysql数据库
/etc/init.d/mysqld stop
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登录mysql数据库
mysql -u root mysql
#4.更新root密码
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';搜索
#最新版MySQL请采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
#5.刷新权限 
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重启mysql
/etc/init.d/mysqld restart
#8.使用root用户重新登录mysql
mysql -uroot -p 
Enter password: <输入新设的密码newpassword>

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注