CentOS6.5系统下Mysql安装
CentOS6.5系统下Mysql安装
傲寒九天 发表于11个月前
CentOS6.5系统下Mysql安装
  • 发表于 11个月前
  • 阅读 1
  • 收藏 0
  • 点赞 0
  • 评论 0

华为云·免费上云实践>>>   

摘要: CentOS6.5系统下Mysql安装

下载地址:
http://mysql.mirror.kangaroot.net/Downloads/
http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
其中mysql使用最新的稳定版本,即最新试用版的上一个版本,且非rc或者alpha的版本,Cmake直接用的最新版。

1.上传mysql-5.6.14.tar.gz和cmake-2.8.10.2.tar.gz到/usr/local文件夹下。
2.CentOS安装g++和ncurses-devel
[root@localhost local]#    yum install gcc-c++  

[root@localhost local]#    yum install ncurses-devel

3.cmake的安装
[root@localhost]#    tar -zxv -f cmake-2.8.10.2.tar.gz     // 解压压缩包
[root@localhost local]#    cd cmake-2.8.10.2
[root@localhost cmake-2.8.10.2]#    ./configure
[root@localhost cmake-2.8.10.2]#    make
[root@localhost cmake-2.8.10.2]#    make install

4.将cmake永久加入系统环境变量
用vi在文件/etc/profile文件中增加变量,使其永久有效,
[root@localhost local]#    vi /etc/profile

在文件末尾追加以下两行代码:
PATH=/usr/local/cmake-2.8.10.2/bin:$PATH
export PATH

执行以下代码使刚才的修改生效:
[root@localhost local]#    source /etc/profile

用 export 命令查看PATH值
[root@localhost local]#    echo $PATH

5.创建mysql的安装目录及数据库存放目录
[root@localhost]#    mkdir -p /usr/local/mysql     //安装mysql
[root@localhost]#    mkdir -p /usr/local/mysql/data     //存放数据库

6.创建mysql用户及用户组
[root@localhost]    groupadd mysql
[root@localhost]    useradd -r -g mysql mysql

7.编译安装mysql
[root@localhost local]#    tar -zxv -f mysql-5.6.14.tar.gz     //解压
[root@localhost local]#    cd mysql-5.6.14
[root@localhost mysql-5.6.14]#
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
[root@localhost mysql-5.6.14]#    make
[root@localhost mysql-5.6.14]#    make install

8.检验是否安装成功
[root@localhost mysql-5.6.14]#    cd /usr/local/mysql/
[root@localhost mysql]#     ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
有bin等以上文件的话,恭喜你已经成功安装了mysql。

配置mysql
9.设置mysql目录权限
[root@localhost mysql]# cd /usr/local/mysql    //把当前目录中所有文件的所有者设为root,所属组为mysql
[root@localhost mysql]# chown -R root:mysql .
[root@localhost mysql]# chown -R mysql:mysql data

10.将mysql的启动服务添加到系统服务中
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y

11.创建系统数据库的表
[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql

12.设置环境变量
[root@localhost ~]#    vi /root/.bash_profile
在修改PATH=$PATH:$HOME/bin为:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@localhost ~]# source /root/.bash_profile     //使刚才的修改生效

13.手动启动mysql
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql &     //启动MySQL,但不能停止
mysqladmin -u root -p shutdown     //此时root还没密码,所以为空值,提示输入密码时,直接回车即可。

14.将mysql的启动服务添加到系统服务中
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

15.启动mysql
[root@localhost mysql]# service mysql start
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

启动失败:
我这里是权限问题,先改变权限
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql
如果还不行
 原因
没有初始化权限表
 
3 解决办法
#cd /usr/local/mysql(进入mysql安装目录)
#chown -R mysql.mysql .
#su - mysql
$cd server
$scripts/mysql_install_db
4 本人解决过程
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# chown -R mysql.mysql .
[root@localhost mysql]# su - mysql
[mysql@localhost ~]$ cd /usr/local/mysql
[mysql@localhost mysql]$ scripts/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the ./bin/mysqlbug script!
[mysql@localhost mysql]$ /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 11767
[mysql@localhost mysql]$ 120502 07:01:17 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
120502 07:01:17 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[mysql@localhost mysql]$ /etc/rc.d/init.d/mysql status
MySQL running (11830)                                      [  OK  ]
[mysql@localhost mysql]$ /etc/rc.d/init.d/mysql start
Starting MySQL                                             [  OK  ]

接着启动服务器
[root@localhost mysql]# /etc/init.d/mysql start

16.修改MySQL的root用户的密码以及打开远程连接
[root@localhost mysql]# mysql -u root mysql

mysql> use mysql;
mysql> desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";    //为root添加远程连接的能力
mysql> update user set Password = password('123456') where User='root';    //设置root用户密码
mysql> select Host,User,Password from user where User='root';
mysql> flush privileges;
mysql> exit

17.重新登录
[root@localhost mysql]# mysql -u root -p
Enter password:123456

若还不能进行远程连接,关闭防火墙
[root@localhost]# /etc/rc.d/init.d/iptables stop

ps -ef|grep mysqld


Access denied for user 'root'@'localhost'  解决办法

# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

共有 人打赏支持
粉丝 0
博文 4
码字总数 4349
×
傲寒九天
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: