unbutu20-MySql5.5.37编译安装详解

MySql5.5.37编译安装详解

[下载地址] (https://cdn.mysql.com//archives/mysql-5.5/mysql-5.5.37.tar.gz)
一、创建mysql的安装目录和用户

mkdir -p /usr/local/mysql  #安装mysql
mkdir -p /usr/local/mysql/data   #存放数据库
groupadd mysql
useradd -r -g mysql mysql

二、yum安装依赖库

gcc-c++ ncurses-devel –y g++
#安装错误信息:
CMake Error atcmake/readlineNaNake:83 (MESSAGE):
Curses library notfound.  Please install appropriatepackage,
#解决方法
yum install ncurses-devel
rm CMakeCache.txt
--------------------------
ubuntu 20依赖解决方式
sudo apt-get install libncurses5-dev g++
rm CMakeCache.txt
重新编译

三、编译安装cmake
[下载地址] (https://cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz)

tar -zxv -f cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./configure
make && make install

四、编译安装mysql5.5.37

tar -zxv -f mysql-5.5.37.tar.gz  #解压
cd mysql-5.5.37

#编译参数
[root@localhost mysql-5.5.37]#
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

#执行make命令
make

- 报错 client/mysql.cc:2855:37: error: invalid conversion from 'char' to 'char*' [-fpermissive]
       field_names[i][num_fields*2]= '\0';
       解决方法:
       -  field_names[i][num_fields*2]= '\0';
       + field_names[i][num_fields*2]= NULL;
github 提交记录:https://github.com/MariaDB/server/commit/7338d3f221e33042dfcf5c1a245317aa7cb015a7
make install

五、检查是否安装成功

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。

六、配置mysql5.5.37详细步骤

#把当前目录中所有文件的所有者设为root,所属组为mysql
chown -R root:mysql .
chown -R mysql:mysql data (可选)

#将mysql的启动服务添加到系统服务中
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
#mysql启动出错解决方法
1、问题
[root@localhost mysql]# /etc/rc.d/init.d/mysql statusMySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED][root@localhost mysql]# /etc/rc.d/init.d/mysql startStarting MySQL...The server quit without updating PID file(/usr/local/mysql/data/localhost.localdomain.pid).                              [FAILED]
2、原因
没有初始化权限表
3、解决办法
cd /usr/local/mysql(进入mysql安装目录)chown -R mysql.mysql .
#重新初始化数据库
[root@B2C-test-server mysql]# ./scripts/mysql_install_db--user=mysql
[root@B2C-test-server mysql]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!
#直接输入mysql启动数据库出错:
[root@localhost mysql]# mysql
-bash: mysql: command not found
#解决方法
[root@localhost mysql]# ln -s /usr/local/mysql/bin/mysql/usr/bin/
#修改MySQL的root用户的密码以及打开远程连接
[root@B2C-test-server 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

#重新登录
[root@B2C-test-server mysql]# mysql -u root -p
Enter password:123456
#若还不能进行远程连接,关闭防火墙
[root@B2C-test-server mysql]# /etc/rc.d/init.d/iptables stop

七、设置mysql密码

#方法一:在mysql系统外,使用mysqladmin
[root@B2C-test-server mysql]# mysqladmin -u rootflush-privileges password 'root
#方法一:通过登录mysql系统
[root@B2C-test-server mysql]# mysql -u root -p
Enter password:
mysql> use mysql;
Database changed
mysql> update user set password=password("root")where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4  Warnings: 0
mysql> flush privileges;
mysql> exit;

八、Mysql root密码忘记解决方法

#方法一:
# /etc/init.d/mysqld stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking&
# mysql -uroot mysql
mysql> update user setPassword=Password('newpassword') where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -penter password:
#方法二:
#修改MySQL的登录设置:
#在[mysqld]的段中加上一句:skip-grant-tables

如下:
[root@B2C-test-server mysql]# vi /etc/my.cnf 
[mysqld]            
datadir=/var/lib/mysql    
socket=/var/lib/mysql/mysql.sock    
user=mysql           
skip-grant-tables

#重启mysql
/etc/init.d/mysqld restartStoppingmysqld:            
[  OK  ]Startingmysqld:                                          [  OK  ]
#无密码登录:
# mysql
mysql> use mysql;update user setPassword=Password('root') where User='root';  mysql> flush privileges;
#退出,修改/etc/my.conf,删除skip-grant-tables,重启mysql。搞定

原文地址:https://blog.51cto.com/liangey/1626945

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值