MySQL的简单使用

#vi /etc/sysconfig/network-scripts/ifcfg-eth0 修改ip


#service network restart  重启网卡


# yum install -y wget    安装wget


#yum clean all

#yum makecache


#cd /usr/local/src/  到/usr/local/src/



#wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.53-linux2.6-x86_64.tar.gz

                                                            下载mysql

#tar zxvf mysql-5.5.53-linux2.6-x86_64.tar.gz    解压 mysql文件

#useradd -s /sbin/nologin -M mysql    创建 mysql用户

# mv mysql-5.5.53-linux2.6-x86_64 /usr/local/mysql 把文件移动到/usr/local/mysql

                                                            这个文件是重新命名的

#cd /usr/local/mysql

# ls                                  显示其目录下的文件


bin      data  include        lib  mysql-test  scripts  sql-bench

COPYING  docs  INSTALL-BINARY  man  README      share    support-files

# mkdir -p /data/mysql/              创建一个目录

#chown -R mysql:mysql /data/mysql    修改权限,(且目录下文件的权限一起修改)


# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql  初始化,提示安装libaio

--------------------------------------------------------------------------------

Installing MySQL system tables...

./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory


Installation of system tables failed!  Examine the logs in

/data/mysql for more information.


You can try to start the mysqld daemon with:


    shell> ./bin/mysqld --skip-grant &


and use the command line tool ./bin/mysql

to connect to the mysql database and look at the grant tables:


    shell> ./bin/mysql -u root mysql

    mysql> show tables


Try 'mysqld --help' if you have problems with paths.  Using --log

gives you a log in /data/mysql that may be helpful.


Please consult the MySQL manual section

'Problems running mysql_install_db', and the manual section that

describes problems on your OS.  Another information source are the

MySQL email archives available at http://lists.mysql.com/.


Please check all of the above before submitting a bug report

at http://bugs.mysql.com/

--------------------------------------------------------------------------

#yum install -y libaio  安装 libaio

#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

初始化没有mysql

# echo $? 提示0 证明没有错误

0


[root@localhost mysql]# cp support-files/my-

my-huge.cnf            my-large.cnf            my-small.cnf

my-innodb-heavy-4G.cnf  my-medium.cnf

=================================================================================


[root@localhost mysql]# cp support-files/my-large.cnf  /etc/my.cnf 把my-large.cnf 拷贝到 /etc/my.cnf 下  mysql的配置文件   

cp: overwrite `/etc/my.cnf'? y                  (因为有了这文件)确定覆盖此文件



#cd /usr/local/mysql/  (我所安装的mysql的路径)


[root@localhost mysql]# ls  显示

bin      data  include        lib  mysql-test  scripts  sql-bench

COPYING  docs  INSTALL-BINARY  man  README      share    support-files


[root@localhost mysql]# cp support-files/mysql.server  /etc/init.d/mysqld    /etc/init.d/  目录下面 是需要开机启动的服务的启动文件

support-files/mysql.server【启动文件】  /etc/init.d/mysqld

(把mysql服务启动文件复制到/etc/init.d/mysqld)



mysql]# chmod 755 /etc/init.d/mysqld 给以mysqld文件

【root用户可以可读可写可执行 root用户组和其他用户可以查看文件内容,并执行这个文件】


# vi /etc/init.d/mysqld 编辑这个文件


basedir=/usr/local/mysql

datadir=/data/mysql



[root@localhost mysql]# chkconfig --add mysqld  把MySQL添加到系统服务中



[root@localhost mysql]# chkconfig mysqld on  关闭mysql


【[root@localhost mysql]# chkconfig mysqld start ?????】

可知是哪里错误了?


# ps aux |grep mysql    查看状态

root      2104  0.0  0.0 103244  860 pts/0    S+  22:52  0:00 grep mysql



#service mysqld start  启动MySQL  前者命令敲错了

Starting MySQL.... SUCCESS!

[root@localhost mysql]# ps aux |grep mysql

root      2132  0.0  0.1  11304  1500 pts/0    S    23:05  0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid

mysql    2424  0.4  9.1 747416 93456 pts/0    Sl  23:05  0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306

root      2449  0.0  0.0 103244  864 pts/0    S+  23:06  0:00 grep mysql


在Windows 命令行下 telnet  192.168.11.136 3306


#netstat -tan 查看端口命令

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address              Foreign Address            State

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                  LISTEN

tcp        0      0 127.0.0.1:25                0.0.0.0:*                  LISTEN

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                  LISTEN

tcp        0    64 192.168.11.136:22          192.168.11.107:49910        ESTABLISHED

tcp        0      0 :::22                      :::*                        LISTEN

tcp        0      0 ::1:25                      :::*                        LISTEN

[root@localhost mysql]# service mysqld restart 重新启动MySQL

Shutting down MySQL. SUCCESS!

Starting MySQL.. SUCCESS!

[root@localhost mysql]# ss -tan 查看端口

State      Recv-Q Send-Q                    Local Address:Port                      Peer Address:Port

LISTEN      0      128                                  :::22                                  :::*

LISTEN      0      128                                    *:22  任何人都可以防火墙端口开着                                  *:*

LISTEN      0      100                                  ::1:25                                  :::*

LISTEN      0      100                            127.0.0.1:25                                    *:*

LISTEN      0      50                                    *:3306                                  *:*

ESTAB      0      64                        192.168.11.136:22                      192.168.11.107:49910

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容